All pastes #216104 Raw Edit

Stuff

public text v1 · immutable
#216104 ·published 2006-10-22 23:28 UTC
rendered paste body
class File(models.Model, ScoreManager, LabelManager, MirrorManager):
	category = models.ForeignKey(Category, related_name="file_category", db_index=True)
	name = models.CharField(maxlength=200, core=True)
	author = models.ForeignKey(User, raw_id_admin=True, db_index=True)
	contributors = models.ManyToManyField(User, related_name="file_contributors", db_index=True, filter_interface=models.HORIZONTAL, blank=True, null=True)
	visible = models.BooleanField(default=True)
	post_date = models.DateTimeField(auto_now_add=True)
	last_post_date = models.DateTimeField(auto_now_add=True)
	parent = models.ForeignKey('self', related_name="file_parent", db_index=True, blank=True, null=True, raw_id_admin=True)
	parent_type = models.ForeignKey(ParentType, db_index=True, blank=True, null=True)
	required_files = models.ManyToManyField('self', related_name="required_files_rel", db_index=True, blank=True, null=True)
	optional_files = models.ManyToManyField('self', related_name="optional_files_rel", db_index=True, blank=True, null=True)
	downloads_total = models.PositiveIntegerField(default=0)
	downloads_today = models.PositiveIntegerField(default=0)
	game = models.ForeignKey(Game, db_index=True)
	ratings_score = models.IntegerField(default=0, editable=False)
	ratings_votes = models.IntegerField(default=0, editable=False)
	labels = models.TextField(null=True, editable=False)
	comments_total = models.PositiveIntegerField(default=0, editable=False)

	def __str__(self):
		return self.name

	def get_absolute_url(self):
		return "/%s/files/details/%d/%s/" % (threadlocals.get_current_lang(), self.id, safe_name(self.name))

	def get_edit_url(self):
		return "/%s/files/edit/%d/" % (threadlocals.get_current_lang(), self.id)

	def save(self, new_data):
		super(self, new_data)
		self.propagate()

	class Admin:
		list_display = ('name', 'post_date', 'author', 'category', 'game',)
		list_filter = ('post_date', 'category',)
		search_fields = ['name', 'game',]
	
	class Meta:
		verbose_name = _('File')
		verbose_name_plural = _('Files')
		ordering = ('-post_date',)
		unique_together = (('name', 'game',),)

	class History:
		pass