GithubHelp home page GithubHelp logo

Comments (3)

jrief avatar jrief commented on June 10, 2024

Please retry with this branch: https://github.com/jrief/django-formset/tree/releases/1.0.x
or https://pypi.org/project/django-formset/1.0.dev0/

There the problem with validating unique indices is solved.
Unfortunately it will take a few additional weeks until I can release an official version, because I have to rewrite parts of the documentation.

from django-formset.

Actionb avatar Actionb commented on June 10, 2024

Yes, that works for fields with unique=True.

I think I noticed another related issue: collections for related models do not know their parent instance during validation.

Inline formsets are instantiated with the parent instance of the relation, and that instance is passed on to the model forms as data for the InlineForeignKeyField. This way, the parent id is available for validation - most notably unique_together validation.

This does not happen for collections for related models.
You can work around this when editing existing relations of an existing parent: since model_to_dict includes the parent in the initial data of the relation's model form, you just need to include the formfield for the parent in the model form and it validates properly.
However, this doesn't work when you are adding a 'new parent', or a new relation to an existing parent. You need to validate the model form of the parent first, and then you can grab the form's instance and pass it on to the related collections. For example like it is done in django admin.

Currently when adding a new related object that would violate unique constraints, the validation for unique_together is skipped when the form of the new object is first validated, because the parent field is missing data. Later, when trying to save the duplicate object, the parent instance is available, and a second validation of the form in construct_instance fails as expected due to the unique constraint. The duplicate object is never saved, but the user doesn't know about this, because they are never presented an error.

from django-formset.

jrief avatar jrief commented on June 10, 2024

Please handle separate issues as such, and do not use an existing one for adding new features, otherwise we get confused.
I'm going to close this. Please open a new issue with the new request.

from django-formset.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.