Created
January 6, 2012 00:07
-
-
Save zazk/1568105 to your computer and use it in GitHub Desktop.
Modelos Many to Many
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Banner(AuditableModel): | |
image = models.ImageField(verbose_name="Archivo", upload_to="banner/original") | |
position = models.IntegerField("Orden", default=0) | |
name = models.CharField("Nombre", max_length=120, blank=True) | |
url = models.CharField("Enlace", max_length=220, blank=True) | |
def url_normal(self): | |
url = "{0}/banner/normal/{1}".format(settings.MEDIA_URL, self.image) | |
return url | |
class Meta: | |
""" .""" | |
verbose_name = u'Banner' | |
verbose_name_plural = u'Banners' | |
ordering = ['position'] | |
class Seccion(AuditableModel): | |
name = models.CharField("Nombre", max_length=120) | |
nick = models.CharField("Identificador", max_length=120) | |
url = models.CharField("Enlace", max_length=220, blank=True) | |
descrip = models.TextField("Descripción", blank=True) | |
position = models.IntegerField("Orden", default=0) | |
banner = models.ManyToManyField(Banner, verbose_name=u"Banners",through='SeccionBanner' ) | |
parent_category = models.ForeignKey("self", | |
verbose_name=u"Seccion superior", | |
blank=True, | |
null=True) | |
class Meta: | |
""" .""" | |
verbose_name = u'Seccion' | |
verbose_name_plural = u'Secciones' | |
ordering = ['position'] | |
def __unicode__(self): | |
# print self | |
# full = ' %s' % ( self.name )self.parent_category.name if self.parent_category.name else '' | |
full = ' %s' % ( self.name ) | |
return full | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment