-
Notifications
You must be signed in to change notification settings - Fork 172
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
[Feature] Use slug fields instead of pk in formset templates #251
Comments
Sounds like a legitimate use case. I didn't find any code dealing with PKs with a quick search in this repo. Maybe this is coming from Django itself? You might want to make a custom |
Yes, IMHO it's also a Django-way. We can open any generic views from Django source code and ensure they have support for
Yes, you're right. Why do That's why this feature may be will never implemented in Django itself. (At least until we will see any generic views with fieldsets usage inside in Django source code.) But it can be a good idea to improve it on
Just replace
to
in template and that's all. (Plus So, yes, {{ Features }} will add two hidden input fields per each inline form (pk of feature and fk to survey but it's safe to omit it, fk is needed only for About fk hidden fields: it's possible to use slugs (
This is similar to
|
If we will create additional form field, we need somehow prevent updating value of that field (may be |
Problem
Let's assume, we have two models.
models.py
:Now we would like to use
UpdateWithInlinesView
.Let's view our form html:
We have
Feature
instance ids there for each of formset members. It's acceptable for most of projects but we may want to use slug fields (uid
in this case).We have motivation to do it if we use integer PK (for performance reasons) and would like to prevent marketing tracking from our competitors (they may create new features every month and compare feature ids to each other to answer questions like
how much new surveys do we have in this month
and so on).form html:
Solution
We replace slugs (
uid
s) to ids here during processing POST data.First step: we create
uids
list.Second step: we load
features
list of dicts withid
anduid
data from database based onuids
values.Third step: we replace slugs to id if we know how to do it (we read
features
).Suggestions
django-extra-views
?The text was updated successfully, but these errors were encountered: