Wednesday, May 2, 2012

Modify __unicode__

Hi All

In models.py my table structure is :-

class ABC(models.Model):
    name = models.CharField(max_length=80,blank=True,null=True)
    date_created = models.DateTimeField(blank=True,null=True)
   
    def __unicode__(self):
        return "%s %s" % (self.name, self.date_created)


Let say my first entry is :-
name = django
date_created = 2012-05-02 # it will look like this datetime.datetime(2012, 5, 2, 15, 42, 24)

I want to modify this ABC(__unicode__ method)  object in such a way that whenever i call this object from forms
like this :-

forms.py

efg = forms.ModelChoiceField(queryset= ABC.objects.all())

The dropdown created above should have values like this:-

1) django Wednesday PM 2 May     # Modify dateTimeField which retuen day of week AM or PM and then day and name of month
2) django1 Wednesday PM 2 May
.
.
.
.
and so on ..

How can i modify the __unicode__ method to achieve this ?

If there is other ways to achieve this that involves changing the table structure i won't mind.

Thanks



--
Regards
Nikhil Verma
+91-958-273-3156

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment