Thursday, September 24, 2015

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

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

On 25 Sep 2015 01:53, "eli" <oluueli@gmail.com> wrote:
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!
 



--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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/CACczBUKVO%2BL%2BdBVBrix_OC%3D26_7%2BkEgsB5T5Ys7cZevhaWKPww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment