strange question when i access related object

15 views
Skip to first unread message

daedae11

unread,
Nov 27, 2014, 9:32:47 AM11/27/14
to django...@googlegroups.com
My EventDate model has a ForeignKey to Event shown as follows:

class EventDate( models.Model ): # {{{1
    """ stores dates for events """
    eventdate_name = models.CharField(
            _( u'Name' ), blank = False, null = False,
            max_length = 80, help_text = _(
            "Example: call for papers" ) )
    eventdate_date = models.DateField( _( u'Date' ), blank = False,
            null = False, db_index = True, validators = [validate_year] )
    event = models.ForeignKey( Event, related_name = 'dates' )
    objects = models.GeoManager()

The shell output is:
In [10]: event.dates.create(eventdate_name='start', eventdate_date=datetime.date.today())
Out[10]: <EventDate: 2014-11-27    start>
In [11]: event.dates.all()
Out[11]: []

Why is event.dates.all() empty?

Does anyone have some advance?


James Schneider

unread,
Nov 27, 2014, 4:59:52 PM11/27/14
to django...@googlegroups.com

Try throwing in an event.save() after creating the eventdate_date. The event.dates.all() is spawning a new query, and you are trying to list changes that haven't yet been committed to the database.

-James

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4655197f.1380a.149f1aab0f2.Coremail.daedae11%40126.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages