-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unique_together
doesn't work seamlessly
#7
Comments
WHY? |
Rewritten as a logical if statement… if not exclude and 'sort_order' not in exclude:
exclude = ['sort_order']
else:
exclude = exclude + ['sort_order' ] but, if exclude is None then how could sort_order be in exclude? |
Logic fail. Should be: def validate_unique(self, exclude=None):
if exclude is None:
exclude = ['sort_order']
elif 'sort_order' not in exclude:
exclude = exclude + ['sort_order']
return super(MyModel, self).validate_unique(exclude=exclude) |
Can this not be added to the Orderable object then? |
I am unsure of the implications of ignoring validation on this, especially as it only applies when |
Guess we just mention it in the README then |
An alternative syntax: def validate_unique(self, exclude=None):
exclude = exclude or []
if 'sort_order' not in exclude:
exclude.append('sort_order')
return super().validate_unique(exclude=exclude) |
ZOMBIE thread… |
Still relevant unfortunately. |
To clarify, this is required because otherwise ModelForms (such as in the admin) will reject changes to the |
Note: this still sucks. I think |
Perhaps this would be a good candidate for the Checks framework. |
@meshy any reason not to add this to the |
I don't see why not :) |
For #7 Add Orderable.validate_unique to exclude `sort_order` when it is unique_together with something..
@meshy in terms of ensuring that "the ... the only approach I can think of is to use a metaclass to dynamically add the The biggest issue would be the need for migrations to be created before the library is updated. This could be documented and to mitigate the pain, the app could include a setting to disable this new feature (leaving the |
#53 mitigates the need to add Keeping this issue open to track the need to ensure the |
If your
sort_order
field isunique_together
with something, you need to add:To your model.
The text was updated successfully, but these errors were encountered: