Create a view form capable of saving data into models through FK

27 views
Skip to first unread message

eli

unread,
Sep 24, 2015, 7:54:12 PM9/24/15
to Django users
Hi Guys, 
A noob here,

I have two models, 

class Students(CommonInfo):
    first_name = models.CharField(max_length=75)
    surname = models.CharField(max_length=75)
    class_score = models.ForeignKey(Course, related_name='course')
    exam_score = models.ForeignKey('House')
    ...........................

    def __unicode__(self):

        return u'%s %s' % (
            self.first_name, self.surname)

class Scores(models.Model):
    class_score = models.PositiveIntegerField()
    exam_score =  models.PositiveIntegerField()
    ...........................

I need to create view that would eventually produce a form with first_name, surname intact but the two foreign fields i.e class and exam scores as editable fields to allow users key in data and save(for named students) into the various models. I dont seem to find any concise way of doing this.
More efficient suggestions are welcome.
Thanks in advance!
 



Gergely Polonkai

unread,
Sep 25, 2015, 2:10:44 AM9/25/15
to Django users

Hello,

The most beautiful way (IMHO) is to create a widget type for this. See this answer on SO[1]. I wonder why this is not part of Django yet…

[1] http://stackoverflow.com/a/5155576/1305139

--
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/b1dd4578-ee90-4fff-9623-65c633d2a591%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Elorm Koku

unread,
Sep 25, 2015, 2:30:41 PM9/25/15
to django...@googlegroups.com
Thanks Gergeley, 
You jux ended three days of misery.....


--
Agbeko Frank

+233 0243 013 730




Reply all
Reply to author
Forward
0 new messages