按用户名或id输入

时间:2017-02-04 10:19:42

标签: django django-models

我有这个模特

class Post(models.Model):   
    auth = models.ForeignKey(settings.AUTH_USER_MODEL,default=1)    
    title = models.CharField(max_length=120)    
    DESCSPECSOFT = (
    (u'Null','Null'),
    (u'Phone',u'Phone'),
    (u'Car',u'Car'),
    (u'Laptop',u'Laptop'),
    (u'jops',u'Jops'),
    (u'Electronic',u'Electronic'),
    (u'Clothes',u'Clothes'),
    (u'Makeup',u'Makeup'),
    (u'Furnishings',u'Furnishings'),
    (u'books',u'books'),
    (u'sports',u'sports'),
    (u'Property',u'Property'),
    (u'Other',u'Other'),
    )   
    City = (
    (u'Null','Null'),
    (u'Kosti',u'Kosti'),
    (u'Khartoum',u'Khartoum'),
    (u'Rabbik',u'Rabbik'),
    (u'Duwaim',u'Duwaim'),
    (u'Sinnar',u'Sinnar'),
    (u'Bahri',u'Bahri'),
    (u'Omdurman',u'Omdurman'),
    (u'Sawakin',u'Sawakin'),
    (u'Port Sudan',u'Port Sudan'),
    (u'Kasala',u'Kasala'),
    (u'Madani',u'Madani'),
    (u'Alabid',u'Alabid'),
    )  
    Case = (
    (u'Null','Null'),
    (u'New',u'New'),
    (u'Old',u'Old'),
    (u'Second Hand',u'Second Hand'),
    (u'Other',u'Other'),
    ) 

    Type = models.CharField(choices=DESCSPECSOFT, default='Null',blank = False,null = False,max_length=120)     
    company = models.CharField(max_length=120)  
    dis = models.TextField(default="in here you w,ll write all the discribtion about your product")     
    image = models.ImageField(null=True,blank=True,width_field="width_field", height_field="height_field")  
    width_field = models.IntegerField(default=0)    
    height_field = models.IntegerField(default=0)   
    case = models.CharField(choices=Case, default=99,blank = False,null = False,max_length=120)     
    price = models.BigIntegerField(default=0)   
    city = models.CharField(choices=City, default='Null',blank = False,null = False,max_length=120)     
    address = models.CharField(max_length=120)  
    draft = models.BooleanField(default=False)  
    #pup = models.DateField(auto_now=False,auto_now_add=False ,null=False)  
    date = models.DateTimeField(auto_now=True ,auto_now_add=False)  
    puplis = models.DateTimeField(auto_now=False ,auto_now_add=True)

    objects = PostManager()

    def __str__(self):      
        return self.title

    def __unicode__(self):      
        return self.title

任何用户都可以添加帖子但我希望用户名显示在数据库中意味着用户如何添加帖子,因为每个帖子显示管理员名称而不是用户如何添加帖子可以有人告诉我haw我可以修复这个??? 抱歉,我很难......

0 个答案:

没有答案