Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Licensing your software (run on web server?)
I've been working on a Python program that I'd like to sell. My business model would be temporal/functional licenses, i.e. standard, pro, full that could be monthly, anual or lifetime. I know it is practically impossible to protect your code, especially written in Python, from a good hacker. What I want is just a basic protection against mass copy (it probably won't be well distributed or looked for anyway) I've read a lot already but, honestly, there is so much information that I'm lost. By what I've read so far two models comes into mind: Make it a regular compiled software and use some kind of obsfucation on my code. Furthermore, implement some kind of cryptography to generate serial keys and build a server to test it against every time the software opens or periodically. Implement the software in a web server, which requires a login. The second is the one I'd like to know more, it seems more secure. I've read that there are some frameworks that can enable this like flask or django. Is it really possible to implement this with them? In addition, I don't want my server to get overloaded. For those web-implemented softwares, is it … -
ansible fails to install package.json files , npm fails
name: Run npm install environment: PATH: "/home/{{ user }}/.nvm/v7.0.0/bin:{{ (ansible_env|default({})).PATH|default('') }}" command: npm install args: chdir: /home/{{ user }}/{{ project_directory }}/{{ front_end }}/admin_frontend/ name: Run npm build environment: PATH: "/home/{{ user }}/.nvm/v7.0.0/bin:{{ (ansible_env|default({})).PATH|default('') }}" command: npm run build args: chdir: /home/{{ user }}/{{ project_directory }}/{{ front_end }}/admin_frontend/ While doing npm install over ansible , npm install fails with an error {fatal: [otp]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Shared connection to 10.7.100.157 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n File \"/tmp/ansible_B9e8JL/ansible_module_npm.py\", line 296, in \r\n main()\r\n File \"/tmp/ansible_B9e8JL/ansible_module_npm.py\", line 271, in main\r\n installed, missing = npm.list()\r\n File \"/tmp/ansible_B9e8JL/ansible_module_npm.py\", line 195, in list\r\n data = json.loads(self._exec(cmd, True, False))\r\n File \"/usr/lib/python2.7/json/init.py\", line 339, in loads\r\n return _default_decoder.decode(s)\r\n File \"/usr/lib/python2.7/json/decoder.py\", line 364, in decode\r\n obj, end = self.raw_decode(s, idx=_w(s, 0).end())\r\n File \"/usr/lib/python2.7/json/decoder.py\", line 382, in raw_decode\r\n raise ValueError(\"No JSON object could be decoded\")\r\nValueError: No JSON object could be decoded\r\n", "msg": "MODULE FAILURE", "rc": 1} } -
How to create random (uid) file names for images uploaded with Django-CKEeditor?
I want to create random uid file names for images uploaded with the django-ckeditor/uploader. I've created utils.py in the same folder as settings.py: import uuid def get_name_uid(): ext = filename.split('.')[-1] filename = "%s.%s" % (uuid.uuid4(), ext) return filename I would like to add this "random" file name to settings.py: CKEDITOR_FILENAME_GENERATOR = get_name_uid() How can I do this? I am not sure how to get the filename that is uploaded in the editor. Should I pass the filename from settings.py to utils.py? Or is there a different way to do this? Their documentation says the following: ``CKEDITOR_UPLOAD_PATH = "uploads/"`` When using default file system storage, images will be uploaded to "uploads" folder in your MEDIA_ROOT and urls will be created against MEDIA_URL (/media/uploads/image.jpg). If you want be able for have control for filename generation, you have to add into settings yours custom filename generator. ``` # utils.py def get_filename(filename): return filename.upper() ``` ``` # settings.py CKEDITOR_FILENAME_GENERATOR = 'utils.get_filename' ``` CKEditor has been tested with django FileSystemStorage and S3BotoStorage. There are issues using S3Storage from django-storages. -
Performing migrations with multiple databases in Django
I have 2 databases in my Projects with multiple apps. All apps except for one are using default db, the other one has a separate db. After I ran makemigrations and ./manage.py migrate --database=separate_db_name I still have unapplied migration pending for default database. The question is how can I make this migration only visible for my separate app and not others(that use default db). Thanks Here is my router class S3DatabaseRouter(object): """ Determine how to route calls for s3web_upload_dev database """ def db_for_read(self, model, **hints): """ Attempts to read s3web_upload models to go to s3web_upload_dev """ if model._meta.app_label == 's3web_upload': return 's3web_upload_dev' return None def db_for_write(self, model, **hints): """ Attempts to write s3web_upload models to go to s3web_upload_dev """ if model._meta.app_label == 's3web_upload': return 's3web_upload_dev' return None def allow_migrate(self, db, app_label, model_name=None, **hints): """ Make sure the s3web_upload app only appears in the 's3web_upload_dev' database """ if app_label == 's3web_upload': return db == 's3web_upload_dev' return None -
Django : Migration of polymorphic models back to a single base class
Let's suppose I have a polymorphic model and I want to get rid of it. class AnswerBase(models.Model): question = models.ForeignKey(Question, related_name="answers") response = models.ForeignKey(Response, related_name="answers") class AnswerText(AnswerBase): body = models.TextField(blank=True, null=True) class AnswerInteger(AnswerBase): body = models.IntegerField(blank=True, null=True) When I want to get all the answers I can never access "body" or I need to try to get the instance of a sub-class by trial and error. # Query set of answerBase, no access to body AnswerBase.objects.all() question = Question.objects.get(pk=1) # Query set of answerBase, no access to body (even with django-polymorphic) question.answers.all() I don't want to use django-polymorphic because of performances, because it does not seem to work for foreignKey relation, and because I don't want my model to be too complicated. So I want this polymorphic architecture to become this simplified one : class Answer(models.Model): question = models.ForeignKey(Question, related_name="answers") response = models.ForeignKey(Response, related_name="answers") body = models.TextField(blank=True, null=True) The migrations cannot be created automatically, it would delete all older answers in the database. I've read the Schema Editor documentation but it does not seem there is a buildin to migrate a model to something that already exists. So I want to create my own operation to save the AnswerText and … -
Ignore inline model when saving
I've been looking on the documentation and stackoverflow/forums for a way to ignore the inline children of a model when I save it in django admin. I've been searching for a few days and I can't seem to find an answer. I have a normal tabularinline object: class UserOrdersAdmin(admin.TabularInline): model = Order classes = ['collapse'] And a normal User admin registration: class UserAdmin(BaseUserAdmin): inlines = (UserOrdersAdmin, UserSettingsAdmin) admin.site.unregister(User) admin.site.register(User, UserAdmin) What I simply want is when I press save within the User "change view", it will ignore the inline "UserOrderAdmin" which is inline to UserAdmin. -
Controlling model creation in Django and DRF
Consider the following Django model and DRF-based API: class Disk(models.Model): size = models.IntegerField(...) free_space = models.IntegerField(...) # ---- Serializers ---- # class DiskSerializer(serializers.ModelSerializer): class Meta: model = Disk fields = ('free_space', 'size') read_only_fields = ('size', ) class CreateDiskSerializer(models.Model): class Meta: model = Disk fields = ('size', ) # note, size only! # ---- View ---- # class DisksView(viewsets.ModelViewSet): ... def get_serializer(self): if self.request.method == 'POST': return CreateDiskSerializer else: return DiskSerializer I am trying to implement the idea of initializing the value of free_space field from size on model's creation. The naive approach would be overriding Disk.save() but that is something I would use at the very last resort. Another approach would be creating a custom model manager which overrides .create(), e.g.: class DiskManager(models.Manager): def create(self, **kwargs): if 'free_space' not in kwargs: try: kwargs['free_space'] = kwargs['size'] except KeyError: pass return super().create(**kwargs) Does it look acceptable to you? Is there a better solution? -
Django1.8 and Mongoclient settings.DATABASES is improperly configured.
i am making an application using django 1.8 and mongoengine But when i am trying to configure Django setting.py file to use a Dummy Database , I receive the following error (orahienv) somya@somya-Inspiron-15-3555:/var/www/html/admin_python$ python manage.py runserver Performing system checks... System check identified no issues (0 silenced). July 06, 2017 - 16:57:25 Django version 1.8, using settings 'admin_python.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. Performing system checks... System check identified no issues (0 silenced). July 06, 2017 - 17:00:15 Django version 1.8, using settings 'admin_python.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. <WSGIRequest: GET '/auth/login/?next=/'> Internal Server Error: /auth/login/ Traceback (most recent call last): File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 164, in get_response response = response.render() File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/template/response.py", line 158, in render self.content = self.rendered_content File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/template/response.py", line 135, in rendered_content content = template.render(context, self._request) File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/template/backends/django.py", line 74, in render return self.template.render(context) File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/template/base.py", line 208, in render with context.bind_template(self): File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__ return self.gen.next() File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/template/context.py", line 235, in bind_template updates.update(processor(self.request)) File "/var/www/html/admin_python/admin_app/context_processors.py", line 30, in init_menu if request.user.is_authenticated(): File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/utils/functional.py", line 226, in inner self._setup() File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/utils/functional.py", line 359, in _setup self._wrapped = self._setupfunc() File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/contrib/auth/middleware.py", line 22, in <lambda> request.user … -
Passing Id from CreateView to another function after creating the object
I am creating a Payment object using Django CreateView then I want to pass the id of this object to another view function to make and display some calculations on another template. how can i do that? views.py: class CreatePayment(CreateView): template_name = "inventory/new_payment.html" success_url = reverse_lazy('inventory:payments_page') model = Payments fields = ('payment_number', 'customer','agent', 'amount') html: <body> <form action="{% url 'inventory:new_payment'%}" method="post"> {% csrf_token %} {{form}} <button type="submit", value="Add">Add</button> </form> </body> urls: url(r'newpayment/$', CreatePayment.as_view(), name='new_payment') -
Does sw-precache package works for django?
Does sw-precache package can be used in django or "django-progressive-web-app 0.1" library performs all the task of sw-precache ? -
django.db.utils.IntegrityError: null value in column - but value is not null
I am using Django Rest Framework and in my serialiazers.py class MeetingSerializer(serializers.ModelSerializer): meeting_organiser = serializers.HiddenField(default=serializers.CurrentUserDefault()) class Meta: model = Meeting fields = '__all__' The Meeting model in my models.py is like: class Meeting(models.Model): [some fields here...] meeting_organiser = models.ForeignKey(User, default=1) [more fields here...] However, when I try to do a save() to the Meeting model I get this error: django.db.utils.IntegrityError: null value in column "meeting_organiser" violates not-null constraint I tried to debug and added in the serializers.py: def save(self): print(self.validated_data) and in models.py: def save(self, *args, **kwargs): print(self.meeting_organiser.username) In both cases, the meeting organiser object was not null and it contained the right values. -
Django recursive updates
I have a five models with a is_delete field in a each model. What a right way cascade set this property is_delete for each child model if I set it in a parent model? I know that Django have ON_CASCADE property field for DELETE method. But have the same method for UPDATE? I know about signals but may be another way? Thanks lot. -
Django Make Migration Error No Such Column
I have a pre-existing model that I am now trying to add an additional field too. It wasn't me that made the original field but I have been adding fields to other classes and making migrations fine. I want to add an additional image field to the class Event, there is already an image field on this class so I know it can handle image fields, I have tried changing the name around to see if that was a issue too. Here is the field I want to add: social_media_image = models.ImageField(null=True, blank=True, help_text='Hello World') This is the error I get when i'm trying to make my migration after adding that code to the model: django.db.utils.OperationalError: no such column: posts_event.social_media_image From my understanding of how migrations work there shouldn't be a column called this yet as I haven't made the migration yet that will add it to the DB. I have tried adding a default value to the field as well but with no luck. I have also tried completely removing the DB along with migration files and trying to recreate them. -
Add Users to ManyToManyField in Model?
I'm new to Django! so could be way wrong :) I'm building an event app. I'm trying to add/remove users to a 'host' list in my 'EventProfile' model from 'MyGuest' model using a bootstrap button, i basically want a different host list in each 'EventProfile', i'm using a class method. I can add/delete each object to each specific EventProfile model in the admin but cant seem to do it using a bootstrap button? I keep getting this error "get() returned more than one Host -- it returned 2!" Heres my code please help :) Models.py class MyGuest(models.Model): users = models.ManyToManyField(User) current_user = models.ForeignKey(User, related_name='add_myguest', null=True) @classmethod def make_myguest(cls, current_user, new_myguest): myguest, created = cls.objects.get_or_create(current_user=current_user) myguest.users.add(new_myguest) @classmethod def lose_myguest(cls, current_user, new_myguest): myguest, created = cls.objects.get_or_create(current_user=current_user) myguest.users.remove(new_myguest) class Host(models.Model): users = models.ManyToManyField(User) current_user = models.ForeignKey(User, related_name='add_myguest', null=True) @classmethod def make_host(cls, current_user, new_host): host, created = cls.objects.get_or_create(current_user=current_user) host.users.add(new_host) @classmethod def lose_host(cls, current_user, new_host): host, created = cls.objects.get_or_create(current_user=current_user) host.users.remove(new_host) class EventProfile(models.Model): event = models.CharField(max_length=100) greeting = models.CharField(max_length=100) invitee = models.CharField(max_length=100) description = models.CharField(max_length=100) date = models.CharField(max_length=100) start_time = models.CharField(max_length=100) finish_time = models.CharField(max_length=100) venue = models.CharField(max_length=100) myguest = models.ForeignKey(MyGuest, related_name='add_myguest_profile', null=True) host = models.ForeignKey(Host, related_name='add_host_profile') def __str__(self): return self.event Views.py def event_change_hosts(request, operation, pk): new_host … -
'Models' object has no attribute 'update'
I'm trying to create a new function but I'm getting this Django error : 'SocieteIntervention' object has no attribute 'update' I have several models in my application : class Societe(models.Model): Nom = models.CharField(null= False, max_length=30, verbose_name='Nom de Société') Etat = models.CharField(max_length = 30, choices = CHOIX_ETAT_SOCIETE, null=False, verbose_name="Etat") Adresse = models.CharField(max_length=30, verbose_name='Adresse') Ville = models.CharField(max_length=30, verbose_name='Ville') Zip = models.IntegerField(verbose_name='Code Postal') Region = models.CharField(max_length=30, verbose_name='Région') Pays = CountryField(blank_label='Sélectionner un pays', verbose_name='Pays') Mail = models.CharField(max_length=40, verbose_name='Email') Web = models.CharField(max_length=40, verbose_name='Site Web') Telephone = models.CharField(max_length=20, verbose_name='Téléphone Fixe') Fax = models.CharField(max_length=20, verbose_name='Fax') SIREN = models.BigIntegerField(verbose_name='N° SIREN') SIRET = models.BigIntegerField(verbose_name='N° SIRET') NAF_APE = models.CharField(max_length=5, verbose_name='Code NAF-APE') RCS = models.CharField(max_length = 30, verbose_name='Code RCS') CHOIX_TVA = models.CharField(max_length = 30, choices=CHOIX_TVA, verbose_name='Assujeti à la TVA') TVA = models.CharField(max_length=13, verbose_name='N° TVA Intracommunautaire') Type = models.CharField(max_length = 30, choices = CHOIX_SOCIETE, verbose_name = 'Type de Société') Effectif = models.CharField(max_length = 30, choices = CHOIX_EFFECTIF, verbose_name = 'Effectif') Capital = models.IntegerField(verbose_name = 'Capital de la Société (euros)') Creation = models.DateTimeField(auto_now_add=True) InformationsInstitution = models.CharField(max_length=30, null=False, verbose_name='Informations Institution') Utilisateur = models.CharField(max_length=100, null=False, verbose_name="Utilisateur", default=" ") def save(self, *args, **kwargs): for field_name in ['Nom', 'Ville', 'Region']: val = getattr(self, field_name, False) if val: setattr(self, field_name, val.upper()) super(Societe, self).save(*args, **kwargs) class SocieteContrat(models.Model): Societe = … -
Display table rows according to keywords
I'm struggling with HTML, Javascript and the Django framework. I have a table. In one of the cases of this table, keywords are displayed. I'm doing bioinfo so it's stuff like "cellular_component" etc, but I'll call them item1, item2 and item3. See the code below : I display a list row for each "item". I would like, somewhere else on the page, to have three checkboxes (for item1, item2 and item3). When item1 is checked, only the rows in which item1 exists are displayed. Same for item2 and item3. I'm having a very hard time doing this, because the items are loaded in the table and the checkboxes are outside of it. Here is the code : <ul> <li> <input type="checkbox" > <label for="listcheck"><b>Item 1</b></label> </li> <li> <input type="checkbox" > <label for="listcheck"><b>Item 2</b></label> </li> <li> <input type="checkbox" > <label for="listcheck"><b>Item 3</b></label> </li> </ul> <table> <tr> <td>Foo</td> <td>Fighters</td> <td>Bar</td> <td> <!-- Only displayed if one of the items (see below) is checked in the list above --> <ul> {% for item in django_database %} <li> blahblah (actually a sub-list but whatever) </li> {% endfor %} </ul> </td> </table> I made a JSFiddle. -
django.db.utils.IntegrityError: NOT NULL constraint failed
i'm trying to build a customised registration to my site, so i'm using a sign Up with Profile Model. Traceback: Traceback (most recent call last): File "C:\Python36\lib\site-packages\django\core\handlers\exception.py", line 41, in inner response = get_response(request) File "C:\Python36\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response response = self.process_exception_by_middleware(e, request) File "C:\Python36\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "C:\Users\admin\Desktop\dev1\mysite\mysite\core\views.py", line 74, in complete_profile form.save() File "C:\Python36\lib\site-packages\django\forms\models.py", line 451, in save self.instance.save() File "C:\Python36\lib\site-packages\django\db\models\base.py", line 806, in save force_update=force_update, update_fields=update_fields) File "C:\Python36\lib\site-packages\django\db\models\base.py", line 836, in save_base updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields) File "C:\Python36\lib\site-packages\django\db\models\base.py", line 922, in _save_table result = self._do_insert(cls._base_manager, using, fields, update_pk, raw) File "C:\Python36\lib\site-packages\django\db\models\base.py", line 961, in _do_insert using=using, raw=raw) File "C:\Python36\lib\site-packages\django\db\models\manager.py", line 85, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "C:\Python36\lib\site-packages\django\db\models\query.py", line 1060, in _insert return query.get_compiler(using=using).execute_sql(return_id) File "C:\Python36\lib\site-packages\django\db\models\sql\compiler.py", line 1099, in execute_sql cursor.execute(sql, params) File "C:\Python36\lib\site-packages\django\db\backends\utils.py", line 80, in execute return super(CursorDebugWrapper, self).execute(sql, params) File "C:\Python36\lib\site-packages\django\db\backends\utils.py", line 65, in execute return self.cursor.execute(sql, params) File "C:\Python36\lib\site-packages\django\db\utils.py", line 94, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback) File "C:\Python36\lib\site-packages\django\utils\six.py", line 685, in reraise raise value.with_traceback(tb) File "C:\Python36\lib\site-packages\django\db\backends\utils.py", line 65, in execute return self.cursor.execute(sql, params) File "C:\Python36\lib\site-packages\django\db\backends\sqlite3\base.py", line 328, in execute return Database.Cursor.execute(self, query, params) django.db.utils.IntegrityError: NOT NULL constraint failed: core_profile.user_id i'm … -
Json recognised as String
I am trying to read the response of the server that gives me the following JSON: {"result": "Success", "message": "[{\"model\": \"mysite.userprofile\", \"pk\": 1}, {\"model\": \"mysite.userprofile\", \"pk\": 4}]"} When I try to read it I get as is a String. If I try to parse it is not possible as it gives me Unexpected token o in JSON at position 1 which means that is a Json already. So this code: $.ajax({ type: 'POST', contentType: 'application/json', dataType: 'json', url: '/search/?city=&radius=', success: function (data) { //data = JSON.parse(data); var ul = document.getElementById("contact-list"); console.log("JSON? "+data.message[0]); // Print [ which is the first char for (var x = 0; x < data.message.length; x++){ // iterate throw every character in the message } So inside the properties ('result' and 'message') it appears as there is a String instead of a Json I tried a lot of things nothing work -
Extend built-in django {% include %} tag
I want to use a custom include like this: <script>{% custom_include 'bundle.js' %}</script> def custom_include: if settings.env == 'test' return '' return include('bundle.js') Can I import it from somewhere? -
Django custom save and update
I have a custom save method for a model. class Ticket(models.Model): show = models.ForeignKey(Show) seat = models.ForeignKey(Seat) ref = models.CharField(max_length=100) paid = models.BooleanField(default=False) class Meta: unique_together = ('show', 'seat') def save(self, *args, **kwargs): if self.paid: do_something() In the view I would like to update multiple Ticket objects: Ticket.objects.filter(ref='ref').update(paid=True) But, since this won't call the custom save method. The method do_something() won't be processed. Is there any way to solve this problem? -
Django ORM Cannot filter by reversed foreign key on
I have a weird behaviour on my production server. When I try to filter by reversed foreign key then I receive an error that it is not possible, but locally it works fine, e.g.: class Foo(models.Model): pass class Bar(models.Model): name = models.CharField() foo = models.ForeignKey('Foo', related_name='bars', blank=True, null=True, default=None) Now trying to do: Foo.objects.filter(bars__name=xyz) will result with Cannot resolve keyword 'bars' into field. Choices are: ... I use Ubuntu 16.04 and django 1.8.7 EDIT 1: can it be related to the fact that ForeignKeys are defined using string representation? -
On save edit FK model Django
The task that im trying to complete seems to be very simple and should be straight forward but i am having no look what so ever. I have a table called PartQuotes, now, on save i run a function that gets the averages of all the part quotes, and puts it into a field called avg_quote, simple. When the model is saved(partQuote) I want to update my other model in the same model.py doc called Job. Which is a Fk of the PartQuote model job = models.ForeignKey('jobs.Job', related_name='quote') The value of PartQuote.avg_quote should be saved in the job model instance as job.quote_price I have tried Django Signals but i dont really understand them that well and the django doc doesnt seem to help me. I have also tried to to it as a 'def' in the model. @receiver(post_save, sender=PartQuote) def f(sender, instance, created, **kwargs): instance.quoted_price = '10.00' instance.quoted_time = datetime.now() if self.avg_quote > 0: job = Job.objects.select_related() job.quoted_price = self.avg_quote Job.save() -
Missing 'aud' from claims - Push notifications in Django
I am trying to implement push notifications in my web app. I am using the pywebpush library. I followed this codelab tutorial to set up my push notifications but to fire them through my server I used the pywebpush library. I tried to get my vapid_claims taking reference from this. It states that the 'aud' is to be retrieved from the endpoint in the subscription_info. Open this link for clarification. Now, checking through pdb, I am getting the following exception. Missing 'aud' from claims. 'aud' is the scheme, host and optional port for this transaction e.g. https://example.com:8080 Alternatively, can anyone tell me how will we generate the aud from this endpoint ("https://fcm.googleapis.com/fcm/send/fqMtZMP5GqE:APA91bEKyYNmx83T2_IruAg1olf4zNnyVqL0hpiz8wkVy0ltIxBZ-Dcl4LMg86YBSek9fWhphZIRMqr03G6uonTHF-nyZwypO8JV-sPlDEzjvS9_ce7bGuLYdCnxmhSC6ZYxhFat0sI1"). -
Display models of same app in different app django
I have an app other in django. I have models like PaymentMethods , Currencies , ReasonCodes , DeviceInfo etc in this app.. I want to display few models under a different heading. How can I do this? Do we have to use a library? Tried using django-modeladmin-reorder library. But it doesnt work. Note : I am using Django 1.8 and a library django-material for the admin interface. -
Using Django and Jquery
In addition to this post https://stackoverflow.com/a/17732956 I want to change the order of a list via drag'n'drop and save it afterwards in django backend. For test purposes and comprehension I've used following fiddle: http://jsfiddle.net/LvA2z/#&togetherjs=LvHpjIr7L0 and updated the action of the form with my own action. So, instead of script.php, I used action="{% url 'save_order' %}". In views my function looks like: def save_order(request): if (request.method == 'POST'): list = request.POST['listCSV'] print(list) Basically I want to change the order of list elements and save it afterwards with the result that after refreshing the page the saved order is given. However I do not know, how pass vars from jquery to django site. When I change the order, I have the sorted list in 'listCSV'. How do I pass this result to django site to save it in db?