How to save one field value from a model to another field of a linked model.

16 views
Skip to first unread message

Md. Ohiduzzaman

unread,
Aug 16, 2016, 1:48:36 PM8/16/16
to Django users
I have designed a linked model named Shiftdate as:
class Shiftdate(models.Model):
    shift_date = models.DateField(blank=False,unique=True)
    sit_date = models.ForeignKey(Sitting,
                                on_delete=models.CASCADE)
Using this model I changed sit_date to shift_date which is like: 
Sitting Date     Shifting Date
2016-09-01       Sept. 15, 2016
2016-09-08       Sept. 19, 2016

Now I need to save this shifting date to the Sitting date as sit_date in Sitting model. My Sitting model is:
class Sitting(models.Model):
    sit_date = models.DateField(blank=False,unique=True)
    cut_off_date = models.DateField(null=True, blank=True)
    ballot_date = models.DateField(null=True, blank=True)
    sess_no = models.ForeignKey(Session,
                                 on_delete=models.CASCADE)
    genre = TreeForeignKey('Genre', null=True, blank=True, db_index=True)

I use 
def get_shift_date(self):
            return self.sit_date=self.shift_date 

Fred Stluka

unread,
Aug 17, 2016, 3:36:37 PM8/17/16
to django...@googlegroups.com
Md. Ohiduzzaman,

Looks good so far.  What happens when you try it?

--Fred

Fred Stluka -- mailto:fr...@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8894d393-5d97-4c97-ba56-1a319d93acec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages