1๐
Not sure from you explanation in what context you require this but I have a model which holds a number of key/value pairs used in validator checks and other things. The keys are all needed by each implementation of the project but the values will differ between projects. The values should be maintainable by an admin user. The values usually do not need to change very much once set. Given that, I decided to put them in a model. It is a bit weird but simple enough.
-
You should be able to limit write access to the model to the one row for either your app or your users through your code.
-
only ever reference the first row in the QuerySet
row = MyVariables.objects.all()[0]
Test if there are rows first. if you think there might accidentally be more than one record then make sure it is ordered (but that should never happen if you did (1) correctly.
1๐
There are a couple of apps already dealing with this, check out http://djangopackages.com/grids/g/live-setting/
- [Answered ]-Django: How can I make Form Wizard take in a request object when it creates the forms?
- [Answered ]-Django Textfield maximum size to be displayed
- [Answered ]-Django complicated queryset
- [Answered ]-Employing caching for the first page of a paginated view in Django
- [Answered ]-What's the choice should be done with django_wsgi and wsgi
0๐
Iโm also a bit confused on your goal, but Iโd recommend looking at the Model Instance section of the docs. You should probably look at customizing the validation or cleaning of the model.
If your goal is to only have 1 row flagged in the table for your model: during the validation you can run a query to see if any other row is flagged, and update them to be not flagged. (or delete them).
This question Unique BooleanField value in Django may be helpful.
- [Answered ]-Django Model Won't Validate or Not Installed
- [Answered ]-Django: File permissions media and static files
- [Answered ]-CSRF issue with Microsoft Edge and IE11
- [Answered ]-Translating text from database