Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
convert sum value to percentage by userid django
trying to convert the total sum to percentage by userid. An error pops out when I tried to run. The error is: "unsupported operand type(s) for /: 'dict' and 'int'". Below is my code for Views.py def attStudName(request): students = MarkAtt.objects.values('studName__VMSAcc').annotate(mark=Sum('attendance')) ttlmark = MarkAtt.objects.values('studName__VMSAcc').aggregate(mark=Sum('attendance')) if (ttlmark): ttl = (ttlmark/1100) * 100 context = { 'students' : students, 'ttl' : ttl } return render(request,'show-name.html',context) How do i convert the total sum to a percentage? -
Django LDAP Authentication Group Membership problem
I am trying to implement LDAP authentication for a Django project. There are three different groups which are allowed to log in. user1 is a member of grp1 and user3 is a member of grp3. So they are supposed to be login but while user1 can log in user3 can not!. LDAP directory has Posix standards. Here is the configuration: from django_auth_ldap.config import LDAPSearch, LDAPGroupQuery, PosixGroupType AUTH_LDAP_USER_SEARCH = LDAPSearch( 'cn=Users,dc=company,dc=com', ldap.SCOPE_SUBTREE, '(uid=%(user)s)', ) AUTH_LDAP_GROUP_SEARCH = LDAPSearch( 'cn=Groups,dc=company,dc=com', ldap.SCOPE_SUBTREE, '(objectClass=posixGroup)', ) AUTH_LDAP_GROUP_TYPE = PosixGroupType() AUTH_LDAP_REQUIRE_GROUP = ( LDAPGroupQuery('cn=grp1,cn=Groups,dc=company,dc=com') | LDAPGroupQuery('cn=grp2,cn=Groups,dc=company,dc=com') | LDAPGroupQuery('cn=grp3,cn=Groups,dc=company,dc=com') ) AUTH_LDAP_USER_ATTR_MAP = { 'first_name': 'givenName', 'last_name': 'sn', 'email': 'mail', } AUTH_LDAP_USER_FLAGS_BY_GROUP = { 'is_superuser': 'cn=grp1,cn=Groups,dc=company,dc=com', 'is_active': ( LDAPGroupQuery('cn=grp1,cn=Groups,dc=company,dc=com') | LDAPGroupQuery('cn=grp2,cn=Groups,dc=company,dc=com') | LDAPGroupQuery('cn=grp3,cn=Groups,dc=company,dc=com') ), } Debug output is here: search_s('cn=Users,dc=company,dc=com', 2, '(uid=%(user)s)') returned 1 objects: cn=user3,cn=users,dc=company,dc=com DEBUG 2019-09-21 08:09:13,193 config 378 140589423471392 search_s('cn=Users,dc=company,dc=com', 2, '(uid=%(user)s)') returned 1 objects: cn=user3,cn=users,dc=company,dc=com cn=user3,cn=users,dc=company,dc=com is not a member of cn=grp1,cn=groups,dc=company,dc=com DEBUG 2019-09-21 08:09:13,253 backend 378 140589423471392 cn=user3,cn=users,dc=company,dc=com is not a member of cn=grp1,cn=groups,dc=company,dc=com Caught LDAPError while authenticating user3: NO_SUCH_OBJECT({'desc': 'No such object', 'matched': 'cn=Groups,dc=company,dc=com'},) WARNING 2019-09-21 08:09:13,257 backend 378 140589423471392 Caught LDAPError while authenticating user3: NO_SUCH_OBJECT({'desc': 'No such object', 'matched': 'cn=Groups,dc=company,dc=com'},) search_s('cn=user1,cn=users,dc=company,dc=com', 0, '(objectClass=*)') returned 1 objects: cn=user1,cn=users,dc=company,dc=com DEBUG 2019-09-21 08:44:14,586 config 405 … -
How add multiple fliters to a model
I have inventory, status and transaction tables. Transaction has many to one inventory link and inventroy has one to one relation to status. I am trying to pull all the transaction with check out > 3 sep and inventory which has staus checkout in Django. I am using following syntax to pull in pyton, it give error inventory = Inventory.objects.get(status = 2) transactions1 = Transaction.objects.filter((checkout_time__gt='2019-09-03') and inventory__in=inventory.id) -
Systemctl enabled service does not load at boot
I'm running multiple Django instances and have followed this guide to set it up: running two instances of gunicorn That means that I have a template file (/etc/systemd/system/gunicorn@.service): [Unit] Description=gunicorn daemon After=network.target PartOf=gunicorn.target # Since systemd 235 reloading target can pass through ReloadPropagatedFrom=gunicorn.target [Service] User=ubuntu Group=www-data WorkingDirectory=/home/ubuntu/webapps/%i ExecStart=/home/ubuntu/webapps/djangoenv/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/webapps/%i/kb.sock kb.wsgi:application [Install] WantedBy=gunicorn.target And I am running these instances: systemctl start gunicorn@project1 systemctl start gunicorn@project2 This all works very well. The systems run properly and all is well. However, I have enabled the services: systemctl enable gunicorn@project1 systemctl enable gunicorn@project2 Returning something like: Created symlink /etc/systemd/system/gunicorn.target.wants/gunicorn@project1.service → /etc/systemd/system/gunicorn@.service. So far, so good. However, when I reboot the system these units do NOT go live: systemctl status gunicorn@project1 ● gunicorn@project1.service - gunicorn daemon Loaded: loaded (/etc/systemd/system/gunicorn@.service; indirect; vendor preset: enabled) Active: inactive (dead) dmesg returns no errors, neither does journalctl: # journalctl -u service-gunicorn.service -- Logs begin at Thu 2019-02-28 18:29:51 UTC, end at Sat 2019-09-21 08:31:11 UTC. -- -- No entries -- # journalctl -u service-gunicorn@project1.service -- Logs begin at Thu 2019-02-28 18:29:51 UTC, end at Sat 2019-09-21 08:31:11 UTC. -- -- No entries -- I have tried to re-enable the service but no change either. When I … -
chrome inspect doesnt showing javascript files in my django application
1.My django application when inspected in Google Chrome in sources tab it shows css files but not the JavaScript file. I Included external link in my django code using '{% %}' but not working, even loaded static at top of page. -
Image upload not working with DRF and React
I am trying to implement image upload functionality using React and DRF. I believe it is not working properly. When I tried to upload image with correct format, it is working fine. But when I tried to upload invalid image, in response it is giving me a long error other than I mentioned in code. class ArticleManager(models.Manager): def active(self, *args, **kwargs): return super(ArticleManager, self).filter(draft=False).filter(publish__lte=timezone.now()) class Articles(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) title = models.CharField(max_length=300) short_title = models.CharField(max_length=300, blank=True, default='not available') content = models.TextField() draft = models.BooleanField(default=False) # publish = models.DateField(auto_now=False, auto_now_add=False) publish = models.DateField(auto_now_add=True, blank=True, null=True) read_time = models.IntegerField(default=0) updated = models.DateTimeField(auto_now=True, auto_now_add=False) timestamp = models.DateTimeField(auto_now=False, auto_now_add=True) slug = models.SlugField(unique=True, blank=True) like = models.BooleanField(default=False) image = models.ImageField(null=True, blank=True, upload_to='images/articles/') thumbnail = models.ImageField(null=True, blank=True, upload_to='images/articles/thumbnail/') objects = ArticleManager() def __unicode__(self): return self.title def __str__(self): return self.title class Meta: ordering = ['-timestamp', '-updated'] def save(self, force_insert=False, force_update=False, using=None, update_fields=None): if not self.pk: self.slug = create_slug(Articles, self.title) if self.image: image_type = self.image.name.split('.')[-1] self.image.name = '{}.{}'.format(self.slug.replace('-', '_'), image_type) if not self._get_thumb(): raise ValueError("Thumbnail could not be created") # I am expecting to get this error return super(Articles, self).save( force_insert=force_insert, force_update=force_update, using=using, update_fields=update_fields ) def _get_thumb(self): image = Image.open(self.image) image.thumbnail((200, 200), Image.ANTIALIAS) thumb_name, thumb_extension = os.path.splitext(self.image.name) … -
Create custom page view counter in Django
I want to create my own view counter. I got inspired from django-hitcount. I read all models of this app. In these lines: class HitCountMixin(object): """ HitCountMixin provides an easy way to add a `hit_count` property to your model that will return the related HitCount object. """ @property def hit_count(self): ctype = ContentType.objects.get_for_model(self.__class__) hit_count, created = HitCount.objects.get_or_create( content_type=ctype, object_pk=self.pk) return hit_count I couldn't understand the meaning and usage of ContentType and get_for_model(self.__class__). Can anyone help me? Source of this model is here. -
How to create multiple images for specific product using django ajax jquery
i'm learning django and i'm trying building ecommerce website , I want to build a system that allows users to upload images to specific product in the store so I tried to pass the id of the product in url parameter and try to access that id from my class based view so I can add images to that item, but i had always a problem showing up and i can't figure out what is the problem, This my code urls.py from django.urls import path from item.views import ProgressBarUploadView app_name = 'item' urlpatterns = [ path('progress-bar-upload/<int:pk>/', ProgressBarUploadView.as_view(), name='progress_bar_upload'), ] views.py class ProgressBarUploadView(View): def get(self, request, *args, **kwargs): print(self.kwargs['pk']) # i want to print pk of product photos_list = Photo.objects.all() return render(self.request, 'zwwebsite/item_images_creation.html', {'photos': photos_list}) def post(self, request, *args, **kwargs): time.sleep(1) form = PhotoForm(self.request.POST, self.request.FILES) if form.is_valid(): photo = form.save() print(self.kwargs['pk']) # i want to print pk of product data = {'is_valid': True, 'name': photo.file.name, 'url': photo.file.url} else: data = {'is_valid': False} return JsonResponse(data) models.py class Photo(models.Model): item = models.ForeignKey(Item, null=True,on_delete=models.CASCADE) title = models.CharField(max_length=255, blank=True) file = models.FileField(upload_to='media/item_image') uploaded_at = models.DateTimeField(auto_now_add=True) forms.py class PhotoForm(forms.ModelForm): class Meta: model = Photo fields = ('file', ) my template {% load staticfiles %} <!DOCTYPE html> … -
Setup of the Divio CMS Repositories
The Divio Django CMS offers two servers: TEST and LIVE. Are these also two separate repositories? Or how is this done in the background? I'm wondering because I would have the feeling the LIVE server is its own repository that just pulls from the TEST whenever I press deploy. Is that correct? -
I want to send email to user from API response in Django?
I want to send email to user after this function calling so in first function i m creating customer on razor pay and after fetching customer id i m passing to other function and on. so in this function get_virtual_account() i am getting all the response from API provided by razor-pay and i need to send that response to user who created the account so how can i do that i am not able to send this response in email. def create_razor_customer(data): logger.info("Inside create_razor_customer") headers = {'Content-Type': 'application/json',} data=json.dumps(data) response = requests.post(settings.API_RAZORPAY+'/customers', headers=headers, data=data, auth=(settings.API_RAZORPAY_KEY, settings.API_RAZORPAY_SECRET)) logger.info(json.loads(response.content)) json_response = response.json() customer_id = json_response['id'] logger.info(customer_id) get_razor_customer(customer_id) return response def get_razor_customer(customer_id): logger.info("Inside get_razor_customer") headers = {'Content-Type': 'application/json',} response = requests.get(settings.API_RAZORPAY+'/customers/'+customer_id, headers=headers, auth=(settings.API_RAZORPAY_KEY, settings.API_RAZORPAY_SECRET)) logger.info(json.loads(response.content)) create_razor_virtual_account(customer_id) return response def create_razor_virtual_account(customer_id): logger.info("Inside create_razor_virtual_account") headers = {'Content-Type': 'application/json',} data = {"receivers": {"types": ["bank_account"]},"description": "razorpay","customer_id": customer_id,"close_by": 1761615838,"notes": {"reference_key": "reference_value"}} data=json.dumps(data) response = requests.post(settings.API_RAZORPAY+'/virtual_accounts', headers=headers, data=data, auth=(settings.API_RAZORPAY_KEY, settings.API_RAZORPAY_SECRET)) json_response = response.json() virtual_id = json_response['id'] logger.info(virtual_id) logger.info(json_response) return response def get_virtual_account(virtual_id): logger.info("Inside get_virtual_account") logger.info(virtual_id) headers = {'Content-Type': 'application/json',} response = requests.get(settings.API_RAZORPAY+'/virtual_accounts/'+virtual_id,headers=headers, auth=(settings.API_RAZORPAY_KEY, settings.API_RAZORPAY_SECRET)) json_response = response.json() logger.info(json_response) return response def send_account_details(): logger.info('Inside send_account_details') send_mail('Account Details', 'Details for Razorpay account', settings.EMAIL_HOST_USER, ['abhishek@byond.travel',]) logger.info("sent") return "sent" -
how to check foreign key attribute in one state?
I have two models in my model.py file. like this: class A(models.Model): Name=models.CharField(max_length=20) Number=models.CharField(max_length=20) Address=models.CharField(max_length=20) and class B(models.Model): Person=models.ForeginKey(A,on_delete=models.CASCADE) Code=models.CharField(max_length=20) and now I want check simple query like this, but it's wrong: object=models.B.objects.get(Person_Name='AnyName') +Note: I don't want to use this way: obj=models.A.objects.get(Name='AnyName') obj2=models.B.objects.get(Person=obj) Any other way to get directly? -
How to create a association with a model in the creation of the object?
I would like to know how can I create an other model instance just after having saved the currently model. I'm changing the original context here to post the question, but let's say I have the models above: class Owner(models.Model): name = models.CharField() points = models.IntegerField() class OwnerCars(models.Model): owner = models.ForeignKey(Owner, unique=True) total = models.IntegerField() cars = models.ManyToManyField(Cars) I would like to create the OwnerCars instance just after I have created a Owner instance, it will initialize the OwnerCars with total = 0 and also a empty list of cars. That total is going to be the sum value of all his cars when it get added. If I create a Owner object and right after that make a GET request to OwnerCars it will say that OwnerCars doesn't exist yet :(. When the person create an Owner profile, I need to have that other model to show info for the person in the screen, that's why I need that instance created. BUT..... If anyone got a better idea, I'm open for it, I know it looks like poor design, and maybe that's the problem. -
While using the django-logpipe I'm getting this error "logpipe.exceptions.MissingTopicError"
I'm running the local kafka producer to produce the messages and have created the topic "test_topic" for it. Here I have include the logpipe settings in the settings.py of my Django project.I have also mentioned the bootstrap server as my localhost machine #LOGPIPE SETTINGS in settings.py: INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'logpipe', ] LOGPIPE = { # Required Settings 'OFFSET_BACKEND': 'logpipe.backend.kafka.ModelOffsetStore', 'CONSUMER_BACKEND': 'logpipe.backend.kafka.Consumer', 'PRODUCER_BACKEND': 'logpipe.backend.kafka.Producer', 'KAFKA_BOOTSTRAP_SERVERS': [ 'localhost:9092' ], 'KAFKA_CONSUMER_KWARGS': { 'group_id': 'django-logpipe', }, # Optional Settings # 'KAFKA_SEND_TIMEOUT': 10, # 'KAFKA_MAX_SEND_RETRIES': 0, # 'MIN_MESSAGE_LAG_MS': 0, # 'DEFAULT_FORMAT': 'json', } -
Save a new file in the client machine directory which is selected by a user
I am working on a project(a web application that runs only on local) where a person has to select a folder and certain files are saved in the same folder based on images analysis in the same folder. I thought it would be great if I use web application than a desktop application. I used Django and used webkitdirectory mozdirectory to select a folder in HTML part. Now I need full path of the machine from which user selects the directory( to save some files in the same path). The problem is browsers have a security feature that prevents JavaScript from knowing your file's local full path. Any way I can save new file in the same folder user selects or I have to switch to desktop application like PyQT for it? -
Secure virtual money in django
I am developing a web application where the users can earn some points as a virtual currency which they could use it to buy things instead of using real money. If they do not have enough points they will need to use both points and real money. but my question is: What security measures do I have to keep in mind in order to avoid hackers increasing their points to buy things for free? The project is based on django and postgresql Any advice will be helpful -
Pass field pk of model X instead of model X's pk in ManyToMany serializer
I currently I have a request like this: { // Making request to RemoteTaskSerializer (see below) name: "Test Server", command: "ls", // TaskTarget pk's targets: [ 1, 2] } But instead of passing TaskTarget pk's, I would like to pass RemoteServer(which is a field of TaskTarget) pk's and have TaskTarget's automatically created with that server field. Here are my models/serializes: class TaskTargetSerializer(serializers.ModelSerializer): class Meta: model = TaskTarget fields = ("server",) class RemoteTaskSerializer(serializers.ModelSerializer): # targets = TaskTargetSerializer(many=True) class Meta: model = RemoteTask fields = ("name", "targets", "command", "id") class RemoteTask(models.Model): name = models.CharField(max_length=120, unique=True) targets = models.ManyToManyField(TaskTarget) command = models.TextField() class TaskTarget(models.Model): server = models.ForeignKey("RemoteServer", on_delete=models.CASCADE) output = models.TextField(null=True) class RemoteServer(models.Model): name = models.CharField(max_length=120, unique=True) ip = models.GenericIPAddressField() port = models.PositiveIntegerField() How would I go about this? -
DRf, paginate foreign key field
I wanna do something like below, but the code as it is inefficient, How can I return paginated response of related object? class Bar(models.Model): pass class Foo(models.Model): bar = models.ForeignKey('bar') foo_id = request.data.get('foo_id') foos = Foo.objects.get(id=foo_id) bars = [ foo.bar in foo for foos ] page = self.paginate_queryset(bars) serializer = self.get_serializer(page, many=True) return self.get_paginated_response(serializer.data) -
How to create an authentication system in django for a SQLServer database?
I am recently working in a django project with a SQLServer database. I already connected the database with SQLServer, and I want to make an authentication system for a table I have in that database. I know django comes with a built-in authentication system, but there is no way to tell django to use a specific table in the database to make the authentication, it just seems to look for users in the default admin page. Is there any way for django to look for data inside a specific table in a SQLServer database and validate the information put by an user? -
Comment on Post gets a page not found error, but still post the comment
I have a comment section for my post form. This is all in my post details. When a comment is posted you get a page not found error: http://localhost:8000/post/15/. post fifteen does not exist. Each comment will add to the post but the post in the error increments by one each time. views.py class PostDetail(DetailView): model = Post def get_context_data(self, **kwargs): data = super(PostDetail, self).get_context_data(**kwargs) vc = self.object.view_count self.object.view_count = F('view_count') + 1 self.object.save() self.object.view_count = vc + 1 initial_comment_data = { 'post': self.get_object(), } data['comment_form'] = CommentModelForm(initial=initial_comment_data) return data class CommentCreate(LoginRequiredMixin,CreateView): model = Comment form_class = CommentModelForm def form_valid(self, form): form.instance.author = self.request.user return super().form_valid(form) models.py class Post(models.Model): title = models.CharField(max_length=100)#title of a post content = models.TextField() date_posted = models.DateTimeField(default=timezone.now) author = models.ForeignKey(User, on_delete=models.CASCADE) #if a user is deleted all of their post will be as well view_count = models.IntegerField(default=0) post_files = models.FileField(null = True, blank=True) def __str__(self): return self.title def get_absolute_url(self): return reverse('post-detail', kwargs={'pk': self.pk}) class Comment(models.Model): post = models.ForeignKey('forum.Post', on_delete=models.CASCADE, related_name='comments') author = models.ForeignKey(User, on_delete=models.CASCADE) text = models.TextField(null=True) created_date = models.DateTimeField(default=timezone.now) def __str__(self): return self.text def get_absolute_url(self): return reverse('post-detail', kwargs={'pk': self.pk}) I want the comment to go into the correct post like it does, but with out … -
Django How to retrieve datetime object with timezone from database
I am having a difficult time with all the mumbo-jungo timezone UTC thing in python. In a django form, I create a zumba class(zumba app for a friend) and select the date and time of the class. Say I create the class for September 19, 8pm, and I am in the America/New York zone, so -4h. In the Posgres database, the entry will be 2019-09-20 00:00:00+00 Django shows it correctly in the view, as it can deal with timezone, but when I retrieve the date object afterwards in the code, I always get as if the class is happening on the 20th at midnight. The timezone offset is not taken into account. Here is the database request to retrieve the zumbaclass object. this_class = zumbaClass.objects.get(id=class_id) if I do print(this_class.date.date()) I get 2019-09-20 00:00:00+00:00 Is there a way to get the time taking the timezone into account correctly? -
I get an error while trying to create superuser in Django
I am new to Django and i am trying to create a superuser ( i'm on Linux mint) and everytime i get a very weird error that i did not get with other Django projects. The error is the following : ( I did not modify anything in the django project besides adding my app in the installed apps list and the url of the app in urls.) File "/home/user/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 538, in url_patterns iter(patterns) TypeError: 'module' object is not iterable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "manage.py", line 21, in <module> main() File "manage.py", line 17, in main execute_from_command_line(sys.argv) File "/home/user/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line utility.execute() File "/home/user/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/user/.local/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv self.execute(*args, **cmd_options) File "/home/user/.local/lib/python3.6/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 59, in execute return super().execute(*args, **options) File "/home/user/.local/lib/python3.6/site-packages/django/core/management/base.py", line 332, in execute self.check() File "/home/user/.local/lib/python3.6/site-packages/django/core/management/base.py", line 364, in check include_deployment_checks=include_deployment_checks, File "/home/user/.local/lib/python3.6/site-packages/django/core/management/base.py", line 351, in _run_checks return checks.run_checks(**kwargs) File "/home/user/.local/lib/python3.6/site-packages/django/core/checks/registry.py", line 73, in run_checks new_errors = check(app_configs=app_configs) File "/home/user/.local/lib/python3.6/site-packages/django/core/checks/urls.py", line 13, in check_url_config return check_resolver(resolver) File "/home/user/.local/lib/python3.6/site-packages/django/core/checks/urls.py", line 23, in check_resolver return check_method() File "/home/user/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 398, in check warnings.extend(check_resolver(pattern)) File "/home/user/.local/lib/python3.6/site-packages/django/core/checks/urls.py", line 23, in check_resolver … -
Django root url automaticlly filled
Crazy error. When I go to http://localhost:8000 instead of redirecting to http: // localhost: 8000/catalog/ I get the address in the URL http: // localhost: 8000 / catalog / catalog / catalog / catalog / catalog / catalog / catalog / catalog / catalog / catalog / catalog / catalog / catalog / catalog / catalog / catalog / catalog / catalog / catalog / catalog / The problem is that I removed all urlpatterns from main_app.urls, but anyway, when I access the root url I get this result. I just can’t imagine what an infinite url can generate if my url looks like this now. urlpatterns = [ url(r'^admin/', admin.site.urls), ] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) -
Python/django. Good day friends
Good day friends i am currently working on an online company website that i owned For the online company, companies need to register and post their products and prices while customer need to login to their account brows through different products and pay foe the one that has a better price. Please i will be very happy to have any good tutorial for this kind of project or if someone can send me a sample model for this then i will be happy thanks. I have tried other research options but am unable to find a good one -
DJANGO FORMS.py 'RawQuerySet' object has no attribute 'all'
Hi my problem is the next, I'm trying to do a Forms with filter raw sql but I can't solved this problem 'RawQuerySet' object has no attribute 'all' Forms.py class pruebaForm (forms.Form): userid = forms.ModelChoiceField(queryset = users.objects.raw('SELECT userid FROM groupsmembers WHERE groupid=User.groupid')) softlimit = forms.IntegerField() hardlimit = forms.IntegerField() printerid = forms.ChoiceField() class Meta: model = userpquota Views.py @login_required def asignarcuota_lista (request): f = userpquotaFilter(request.GET, queryset=userpquota.objects.all()) if request.method == "POST": form = pruebaForm(request.POST) if form.is_valid(): asignarcuota = form.save(commit=False) asignarcuota.save() messages.success(request,'Se ha asignadoº correctamente') return redirect('asignarcuota_lista',) else: form = pruebaForm() return render (request, 'pykota/asignarcuota_lista.html', {'filter': f, 'form': form}) -
Reverse back Postgres field type when migrations were applied in Django
I pulled the new code from GitHub and my colleagues changed the type of a field in a Django model from TextField to JSONField. After running python manage.py makemigrations and python manage.py migrate the type of the field was changed in the database (I suppose). I needed to reverse back to previous migration and somehow the type of the field was not reversed. How could I fix the issue? Why reversing back migration does not revert back the field type?