Django form: reference fields from foreign keyform for simultaneously editing two django models with foreign key relationshipdjango - inlineformset_factory with more than one ForeignKeyHow to remove a key from a Python dictionary?How to temporarily disable a foreign key constraint in MySQL?What is wrong with my models.py?Radio buttons in django adminCreate a new model which have all fields of currently existing modelDjango foreign keys : settings.AUTH_USER_MODEL keeps giving null for form.saveHow to expose some specific fields of model_b based on a field of model_a?How to set dynamic initial values to django modelform fieldrelated name in parent model in django if inherited in other model

How to deal with apathetic co-worker?

What ways have you found to get edits from non-LaTeX users?

A planet of ice and fire

How to signal to my players that the following part is supposed to be played on fast forward?

What is wrong with this proof that symmetric matrices commute?

How can I get an unreasonable manager to approve time off?

What is the highest possible permanent AC at character creation?

How did old MS-DOS games utilize various graphic cards?

Watts vs. volts amperes

Why would future John risk sending back a T-800 to save his younger self?

At what point in time did Dumbledore ask Snape for this favor?

What is the actual quality of machine translations?

Are there any instruments that don't produce overtones?

How is water heavier than petrol, even though its molecular weight is less than petrol?

Is counterpoint still used today?

How come the nude protesters were not arrested?

Does Disney no longer produce hand-drawn cartoon films?

How can I tell the difference between unmarked sugar and stevia?

English word for "product of tinkering"

Winning Strategy for the Magician and his Apprentice

Source that a married woman seduced by a “messianic figure” is still permitted to her husband

How to handle self harm scars on the arm in work environment?

What is the highest possible temporary AC at level 1, without any help from others?

Universal hash functions with homomorphic XOR property



Django form: reference fields from foreign key


form for simultaneously editing two django models with foreign key relationshipdjango - inlineformset_factory with more than one ForeignKeyHow to remove a key from a Python dictionary?How to temporarily disable a foreign key constraint in MySQL?What is wrong with my models.py?Radio buttons in django adminCreate a new model which have all fields of currently existing modelDjango foreign keys : settings.AUTH_USER_MODEL keeps giving null for form.saveHow to expose some specific fields of model_b based on a field of model_a?How to set dynamic initial values to django modelform fieldrelated name in parent model in django if inherited in other model






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm making a task tracker webapp (the full source code is also available) and I have a database structure where each task has a title, a description, and some number of instances, that can each be marked incomplete/incomplete:



class Task(models.Model):
title = OneLineTextField()
description = models.TextField(blank=True)


class TaskInstance(models.Model):
task = models.ForeignKey(Task, on_delete=models.CASCADE)
is_complete = models.BooleanField()


The task and the instances can be shared separately, although access to the instance should imply read access to the task. This is intended for classroom situations, where the teacher creates a task and assigns it to their students.



class TaskPermission(models.Model):
task = models.ForeignKey(Task, on_delete=models.CASCADE, related_name='permissions')
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='task_permissions_granted')
shared_by = models.ForeignKey(User, on_delete=models.PROTECT, null=True, related_name='task_permissions_granting')
can_edit = models.BooleanField(default=False)

class Meta:
unique_together = 'task', 'user', 'shared_by',


class TaskInstancePermission(models.Model):
task_instance = models.ForeignKey(TaskInstance, on_delete=models.CASCADE, related_name='permissions')
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='task_instance_permissions_granted')
shared_by = models.ForeignKey(User, on_delete=models.PROTECT, null=True, related_name='task_instance_permissions_granting')
can_edit = models.BooleanField(default=False)

class Meta:
unique_together = 'task_instance', 'user', 'shared_by',


My question is how to create a form for TaskInstances with fields for its is_complete, as well as its Task's title and description. Would something like this work? Or would I need to implement my own save and clean methods?



class TaskForm(ModelForm):
class Meta:
model = TaskInstance
fields = ('is_complete', 'task__title', 'task__description')









share|improve this question
























  • You don't need to implement them unless you want to override them

    – ruddra
    Mar 24 at 17:16











  • I don't really understand your requirements. An arbitrary title and description need not correspond to any Task instance. It would be more normal to simply select the task from a list of existing ones - which you can easily get to display them using title and/or description. This all comes down to how you want the user interface to work.

    – Robin Zigmond
    Mar 24 at 17:18











  • @RobinZigmond I see what you're saying. However, I was thinking of having each task have a list of instances, so it goes in the other direction. It would then be possible to modify the task's title & description from the task instance. I might reconsider that, but I want to simplify things for the case of one instance per task, though...

    – Solomon Ucko
    Mar 24 at 17:32






  • 1





    Oh, so you want a page for editing a particular TaskInstance instance, in which you can change the title and description of the underlying task? That's perfectly possible (if you don't mind the "action at a distance" of one instance affecting every other based on the same Task) - in that case use a regular Form rather than a ModelForm and do all the necessary database inserts/updates in your view.

    – Robin Zigmond
    Mar 24 at 17:36






  • 1





    Possible duplicate of form for simultaneously editing two django models with foreign key relationship

    – Paandittya
    Mar 24 at 21:54

















0















I'm making a task tracker webapp (the full source code is also available) and I have a database structure where each task has a title, a description, and some number of instances, that can each be marked incomplete/incomplete:



class Task(models.Model):
title = OneLineTextField()
description = models.TextField(blank=True)


class TaskInstance(models.Model):
task = models.ForeignKey(Task, on_delete=models.CASCADE)
is_complete = models.BooleanField()


The task and the instances can be shared separately, although access to the instance should imply read access to the task. This is intended for classroom situations, where the teacher creates a task and assigns it to their students.



class TaskPermission(models.Model):
task = models.ForeignKey(Task, on_delete=models.CASCADE, related_name='permissions')
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='task_permissions_granted')
shared_by = models.ForeignKey(User, on_delete=models.PROTECT, null=True, related_name='task_permissions_granting')
can_edit = models.BooleanField(default=False)

class Meta:
unique_together = 'task', 'user', 'shared_by',


class TaskInstancePermission(models.Model):
task_instance = models.ForeignKey(TaskInstance, on_delete=models.CASCADE, related_name='permissions')
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='task_instance_permissions_granted')
shared_by = models.ForeignKey(User, on_delete=models.PROTECT, null=True, related_name='task_instance_permissions_granting')
can_edit = models.BooleanField(default=False)

class Meta:
unique_together = 'task_instance', 'user', 'shared_by',


My question is how to create a form for TaskInstances with fields for its is_complete, as well as its Task's title and description. Would something like this work? Or would I need to implement my own save and clean methods?



class TaskForm(ModelForm):
class Meta:
model = TaskInstance
fields = ('is_complete', 'task__title', 'task__description')









share|improve this question
























  • You don't need to implement them unless you want to override them

    – ruddra
    Mar 24 at 17:16











  • I don't really understand your requirements. An arbitrary title and description need not correspond to any Task instance. It would be more normal to simply select the task from a list of existing ones - which you can easily get to display them using title and/or description. This all comes down to how you want the user interface to work.

    – Robin Zigmond
    Mar 24 at 17:18











  • @RobinZigmond I see what you're saying. However, I was thinking of having each task have a list of instances, so it goes in the other direction. It would then be possible to modify the task's title & description from the task instance. I might reconsider that, but I want to simplify things for the case of one instance per task, though...

    – Solomon Ucko
    Mar 24 at 17:32






  • 1





    Oh, so you want a page for editing a particular TaskInstance instance, in which you can change the title and description of the underlying task? That's perfectly possible (if you don't mind the "action at a distance" of one instance affecting every other based on the same Task) - in that case use a regular Form rather than a ModelForm and do all the necessary database inserts/updates in your view.

    – Robin Zigmond
    Mar 24 at 17:36






  • 1





    Possible duplicate of form for simultaneously editing two django models with foreign key relationship

    – Paandittya
    Mar 24 at 21:54













0












0








0








I'm making a task tracker webapp (the full source code is also available) and I have a database structure where each task has a title, a description, and some number of instances, that can each be marked incomplete/incomplete:



class Task(models.Model):
title = OneLineTextField()
description = models.TextField(blank=True)


class TaskInstance(models.Model):
task = models.ForeignKey(Task, on_delete=models.CASCADE)
is_complete = models.BooleanField()


The task and the instances can be shared separately, although access to the instance should imply read access to the task. This is intended for classroom situations, where the teacher creates a task and assigns it to their students.



class TaskPermission(models.Model):
task = models.ForeignKey(Task, on_delete=models.CASCADE, related_name='permissions')
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='task_permissions_granted')
shared_by = models.ForeignKey(User, on_delete=models.PROTECT, null=True, related_name='task_permissions_granting')
can_edit = models.BooleanField(default=False)

class Meta:
unique_together = 'task', 'user', 'shared_by',


class TaskInstancePermission(models.Model):
task_instance = models.ForeignKey(TaskInstance, on_delete=models.CASCADE, related_name='permissions')
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='task_instance_permissions_granted')
shared_by = models.ForeignKey(User, on_delete=models.PROTECT, null=True, related_name='task_instance_permissions_granting')
can_edit = models.BooleanField(default=False)

class Meta:
unique_together = 'task_instance', 'user', 'shared_by',


My question is how to create a form for TaskInstances with fields for its is_complete, as well as its Task's title and description. Would something like this work? Or would I need to implement my own save and clean methods?



class TaskForm(ModelForm):
class Meta:
model = TaskInstance
fields = ('is_complete', 'task__title', 'task__description')









share|improve this question
















I'm making a task tracker webapp (the full source code is also available) and I have a database structure where each task has a title, a description, and some number of instances, that can each be marked incomplete/incomplete:



class Task(models.Model):
title = OneLineTextField()
description = models.TextField(blank=True)


class TaskInstance(models.Model):
task = models.ForeignKey(Task, on_delete=models.CASCADE)
is_complete = models.BooleanField()


The task and the instances can be shared separately, although access to the instance should imply read access to the task. This is intended for classroom situations, where the teacher creates a task and assigns it to their students.



class TaskPermission(models.Model):
task = models.ForeignKey(Task, on_delete=models.CASCADE, related_name='permissions')
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='task_permissions_granted')
shared_by = models.ForeignKey(User, on_delete=models.PROTECT, null=True, related_name='task_permissions_granting')
can_edit = models.BooleanField(default=False)

class Meta:
unique_together = 'task', 'user', 'shared_by',


class TaskInstancePermission(models.Model):
task_instance = models.ForeignKey(TaskInstance, on_delete=models.CASCADE, related_name='permissions')
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='task_instance_permissions_granted')
shared_by = models.ForeignKey(User, on_delete=models.PROTECT, null=True, related_name='task_instance_permissions_granting')
can_edit = models.BooleanField(default=False)

class Meta:
unique_together = 'task_instance', 'user', 'shared_by',


My question is how to create a form for TaskInstances with fields for its is_complete, as well as its Task's title and description. Would something like this work? Or would I need to implement my own save and clean methods?



class TaskForm(ModelForm):
class Meta:
model = TaskInstance
fields = ('is_complete', 'task__title', 'task__description')






python django django-models django-forms django-model-field






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 18:06







Solomon Ucko

















asked Mar 24 at 17:09









Solomon UckoSolomon Ucko

1,12121122




1,12121122












  • You don't need to implement them unless you want to override them

    – ruddra
    Mar 24 at 17:16











  • I don't really understand your requirements. An arbitrary title and description need not correspond to any Task instance. It would be more normal to simply select the task from a list of existing ones - which you can easily get to display them using title and/or description. This all comes down to how you want the user interface to work.

    – Robin Zigmond
    Mar 24 at 17:18











  • @RobinZigmond I see what you're saying. However, I was thinking of having each task have a list of instances, so it goes in the other direction. It would then be possible to modify the task's title & description from the task instance. I might reconsider that, but I want to simplify things for the case of one instance per task, though...

    – Solomon Ucko
    Mar 24 at 17:32






  • 1





    Oh, so you want a page for editing a particular TaskInstance instance, in which you can change the title and description of the underlying task? That's perfectly possible (if you don't mind the "action at a distance" of one instance affecting every other based on the same Task) - in that case use a regular Form rather than a ModelForm and do all the necessary database inserts/updates in your view.

    – Robin Zigmond
    Mar 24 at 17:36






  • 1





    Possible duplicate of form for simultaneously editing two django models with foreign key relationship

    – Paandittya
    Mar 24 at 21:54

















  • You don't need to implement them unless you want to override them

    – ruddra
    Mar 24 at 17:16











  • I don't really understand your requirements. An arbitrary title and description need not correspond to any Task instance. It would be more normal to simply select the task from a list of existing ones - which you can easily get to display them using title and/or description. This all comes down to how you want the user interface to work.

    – Robin Zigmond
    Mar 24 at 17:18











  • @RobinZigmond I see what you're saying. However, I was thinking of having each task have a list of instances, so it goes in the other direction. It would then be possible to modify the task's title & description from the task instance. I might reconsider that, but I want to simplify things for the case of one instance per task, though...

    – Solomon Ucko
    Mar 24 at 17:32






  • 1





    Oh, so you want a page for editing a particular TaskInstance instance, in which you can change the title and description of the underlying task? That's perfectly possible (if you don't mind the "action at a distance" of one instance affecting every other based on the same Task) - in that case use a regular Form rather than a ModelForm and do all the necessary database inserts/updates in your view.

    – Robin Zigmond
    Mar 24 at 17:36






  • 1





    Possible duplicate of form for simultaneously editing two django models with foreign key relationship

    – Paandittya
    Mar 24 at 21:54
















You don't need to implement them unless you want to override them

– ruddra
Mar 24 at 17:16





You don't need to implement them unless you want to override them

– ruddra
Mar 24 at 17:16













I don't really understand your requirements. An arbitrary title and description need not correspond to any Task instance. It would be more normal to simply select the task from a list of existing ones - which you can easily get to display them using title and/or description. This all comes down to how you want the user interface to work.

– Robin Zigmond
Mar 24 at 17:18





I don't really understand your requirements. An arbitrary title and description need not correspond to any Task instance. It would be more normal to simply select the task from a list of existing ones - which you can easily get to display them using title and/or description. This all comes down to how you want the user interface to work.

– Robin Zigmond
Mar 24 at 17:18













@RobinZigmond I see what you're saying. However, I was thinking of having each task have a list of instances, so it goes in the other direction. It would then be possible to modify the task's title & description from the task instance. I might reconsider that, but I want to simplify things for the case of one instance per task, though...

– Solomon Ucko
Mar 24 at 17:32





@RobinZigmond I see what you're saying. However, I was thinking of having each task have a list of instances, so it goes in the other direction. It would then be possible to modify the task's title & description from the task instance. I might reconsider that, but I want to simplify things for the case of one instance per task, though...

– Solomon Ucko
Mar 24 at 17:32




1




1





Oh, so you want a page for editing a particular TaskInstance instance, in which you can change the title and description of the underlying task? That's perfectly possible (if you don't mind the "action at a distance" of one instance affecting every other based on the same Task) - in that case use a regular Form rather than a ModelForm and do all the necessary database inserts/updates in your view.

– Robin Zigmond
Mar 24 at 17:36





Oh, so you want a page for editing a particular TaskInstance instance, in which you can change the title and description of the underlying task? That's perfectly possible (if you don't mind the "action at a distance" of one instance affecting every other based on the same Task) - in that case use a regular Form rather than a ModelForm and do all the necessary database inserts/updates in your view.

– Robin Zigmond
Mar 24 at 17:36




1




1





Possible duplicate of form for simultaneously editing two django models with foreign key relationship

– Paandittya
Mar 24 at 21:54





Possible duplicate of form for simultaneously editing two django models with foreign key relationship

– Paandittya
Mar 24 at 21:54












1 Answer
1






active

oldest

votes


















0














I think inlineformset_factory is what I'm looking for!



Actually, it does not seem to be useful: it is for multiple forms of the same type, not different types...






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55326345%2fdjango-form-reference-fields-from-foreign-key%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I think inlineformset_factory is what I'm looking for!



    Actually, it does not seem to be useful: it is for multiple forms of the same type, not different types...






    share|improve this answer





























      0














      I think inlineformset_factory is what I'm looking for!



      Actually, it does not seem to be useful: it is for multiple forms of the same type, not different types...






      share|improve this answer



























        0












        0








        0







        I think inlineformset_factory is what I'm looking for!



        Actually, it does not seem to be useful: it is for multiple forms of the same type, not different types...






        share|improve this answer















        I think inlineformset_factory is what I'm looking for!



        Actually, it does not seem to be useful: it is for multiple forms of the same type, not different types...







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 25 at 18:54

























        answered Mar 24 at 22:45









        Solomon UckoSolomon Ucko

        1,12121122




        1,12121122





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55326345%2fdjango-form-reference-fields-from-foreign-key%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript