Exemplo n.º 1
0
class CurrentManager(models.Manager):
    def get_query_set(self):
        return super(CurrentManager, self).get_query_set().filter(expiration__gte=datetime.date.today())

class Coupon(models.Model):
    name = models.CharField(max_length=100, help_text='Maximum 100 characters.')
    offer = models.CharField(max_length=100, help_text='Maximum 100 characters.')
    slug = models.SlugField(unique=True)
    description = models.TextField()
    productshot = models.ImageField(upload_to='static/productshot')	
    company = models.ForeignKey(Company)	
    expiration = models.DateTimeField()
    

    objects = models.Manager()
    current = CurrentManager()

    class Meta:
        verbose_name_plural = "Coupons"	
    
    def get_absolute_url(self):
        return "/%s/%s/" % (self.company.slug, self.slug)

    def __unicode__(self):
        return self.offer
        
import categories

categories.register_fk(Coupon, 'primary_category', {'related_name':'coupon_primary_set'})
categories.register_m2m(Coupon, 'categories', )        
Exemplo n.º 2
0
# Create your models here.

class SimpleText(models.Model):
    """
    (SimpleText description)
    """
    
    name        = models.CharField(max_length=255)
    description = models.TextField(blank=True)
    created     = models.DateTimeField(auto_now_add=True)
    updated     = models.DateTimeField(auto_now=True)
    
    class Meta:
        verbose_name_plural = 'Simple Text'
        ordering = ('-created',)
        get_latest_by = 'updated'
    
    def __unicode__(self):
        return self.name
    
    # If using the get_absolute_url method, put the following line at the top of this file:
    from django.db.models import permalink
    
    @permalink
    def get_absolute_url(self):
        return ('simpletext_detail_view_name', [str(self.id)])

import categories

categories.register_fk(SimpleText, 'primary_category', {'related_name':'simpletext_primary_set'})
categories.register_m2m(SimpleText, 'cats', )