Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
How to handle PUT request in Django RestFramework
I am trying to update my data in 'VoterList' model by using PUT api, but i don't know which function should i use in my 'views.py' file to handle the coming PUT request because in PUT api, we use parameters from URL to pick the relevent entry from model for updation and then update it by using data received from PUT api. model.py class VoterList(models.Model): # id = models.IntegerField(auto_created= True, primary_key=True) name = models.CharField( max_length=20) email = models.EmailField() mobile = models.IntegerField() city = models.CharField( max_length=20) type = models.CharField(max_length=20) def __str__(self): return self.name serializers.py class FillVoterListSerializers(serializers.HyperlinkedModelSerializer): class Meta: model = VoterList fields = ('id','name', 'email', 'mobile', 'city', 'type') def update(self, instance, validated_data): instance.name = validated_data.pop("name", instance.name) instance.email = validated_data.pop("email", instance.email) instance.save() return instance I will manage the code for PUT in serializers by myself. views.py class UpdateVoter(APIView): serializer_class = FillVoterListSerializers permission_classes = (AllowAny,) def post(self, request,*args,**kwargs): isDataExist = VoterList.objects.get(id=request.data.get('id')) if not isDataExist: return Response({"message":"No Voter exist with this id."}) else: isDataUpdated = self.serializer_class(isDataExist, request.data, partial=True) if isDataUpdated.is_valid(): isDataUpdated.save() return Response({"message": "Voter updated."}) else: return Response({"message": "All fields are Mandatory."}) urls.py urlpatterns = [ url('api/updateVoter/(?P<id>[0-9]+)/$', UpdateVoter.as_view(), name= "updateVoter")] So what code should i write in my view.py to handle the PUT request. β¦ -
Setting form ChoiceField to dynamically generated list
I have a Javascript function that dynamically generates a time list. While the function works properly, its values never pass form.is_valid because they are not part of my forms.ChoiceField(choices=xyz). I was wondering how I would reference a client side Javascript function in choices= forms.py booked_time = forms.ChoiceField(choices=options, widget=forms.Select(attrs={'class' : 'form-control', 'id' : 'time', 'required' : 'True'})) Javascript var length = document.getElementById('length'); var chosenLength = length.options[length.selectedIndex].value; var start = document.getElementById('start').innerHTML.split('.').join('').toLocaleLowerCase(); var end = document.getElementById('end').innerHTML.split('.').join('').toLocaleLowerCase(); var time = document.getElementById('time'); time.disabled = true; function disabled() { if (chosenLength.value != "") { time.disabled = false; } } var slotTimes = []; document.getElementById("length").onchange = function(evt){ var timeDistance = evt.target.value; var startMoment = moment(start, "h:mm a"); var endMoment = moment(end, "h:mm a"); slotTimes = []; while (startMoment.isSameOrBefore(endMoment)) { slotTimes.push(startMoment.format("h:mm a")); startMoment = startMoment.add(timeDistance, 'minutes'); } addDropdown(); }; function addDropdown() { var doc = '', times = slotTimes, i; for (i = 0; i < times.length; i++) { doc += "<option value='" + times[i] + "'>" + times[i] + "</option>"; } document.getElementById('time').innerHTML = doc; disabled(); } -
Overriding PrimaryKeyRelatedField to serialize a null RelatedField object based on request
Can anyone suggest how I can serialize the following type of null related field to give a serialized JSON object list which isn't null on get request class SomeModel(models.Model): a_fk = models.ForeignKey(ForeignObj1, null=True, on_delete=models.CASCADE) b_fk = models.ForeignKey(ForeignObj2, null=True, on_delete=models.CASCADE) class SomeSerializer(serializers.ModelSerializer): class Meta: model = SomeModel fields = ['a_fk', 'b_fk'] What I get/see in browsable API JSON is { "a_fk": null, "b_fk": null } but the fields queryset are fetched on the browsable API form for POST request just like normal django forms What I will like to see is the actual list of available queryset objects on those fields returned on get request, even though it's null, if I override the PrimaryKeyRelatedField init(), which I did, printing the fields still returned empty queryset, which means it's still treating the field as null. I have gone through the source codes and still can't figure out how to make this happen dynamically on get request P.S The fields have to remain null due to some business use case. Any nudge in the right direction will be greatly appreciated -
How to get the value of the key in the serializer in manytomanyfield in Django Rest Framework?
I have some problem on displaying the data during serialization. This is my model: from django.db import models class Paradigmn(models.Model): name = models.CharField(max_length=50) def __str__(self): return self.name class Language(models.Model): name = models.CharField(max_length=50) paradigm = models.ForeignKey(Paradigmn, on_delete=models.CASCADE) def __str__(self): return self.name class Programmer(models.Model): name = models.CharField(max_length=50) languages = models.ManyToManyField(Language, related_name='languages') def __str__(self): return self.name And this is my serializer: from languages.models import Language, Paradigmn, Programmer class LanguageSerializer(serializers.ModelSerializer): paradigms = serializers.ReadOnlyField(source='paradigm.name') class Meta: model = Language fields = ('id', 'name', 'paradigms') class ParadigmnSerializer(serializers.ModelSerializer): class Meta: model = Paradigmn fields = ('id', 'name',) class ProgrammerSerializer(serializers.ModelSerializer): languages = LanguageSerializer(many=True, read_only=True) class Meta: model = Programmer fields = ('id', 'name', 'languages') And this is the result: [ { "id": 1, "name": "Ryan", "languages": [ { "id": 1, "name": "Java", "paradigms": "Object-Oriented" } ] }, { "id": 2, "name": "Jean", "languages": [ { "id": 3, "name": "Python", "paradigms": "Object-Oriented" } ] }, { "id": 3, "name": "Michael", "languages": [ { "id": 2, "name": "Elixir", "paradigms": "Functional" } ] } I just want to show on the languages array, the name of the language instead of the all the details of the language array. What is the best solution for this? Thank you in advance. -
Django databases. What do you think about oracle?
I have questions. I would like to choose datebase for django and I think that oracle is good base. What are you think about oracle? -
Form not accepting time value as valid
I have a form that takes booked_lesson as a TimeField, but I input it using a forms.ChoiceField because it is dynamically created using a Javascript function. I get an error like, "booked_time": ["Select a valid choice. 6:15 pm is not one of the available choices."], when I submit the form. The issue is, that my database accepts times like 6:15 pm, and I have several instances of that saved, but it won't save in this view. I feel that the problem might be in how my form or Javascript function is interpreted. I would appreciate any help with this. HTML <div class="row"> <div class="col-md-5 mx-auto border" id="box"> <!-- Form --> <form action="{% url 'view:book_lesson' lesson.id %}" method="POST" autocomplete="off"> {% csrf_token %} <div class="hidden"> {% load tz %} {% timezone user.time_zone %} <p><span id="start">{{ lesson.lesson_datetime_start|time }}</span></p> <p><span id="end">{{ lesson.lesson_datetime_end|time }}</span></p> {% endtimezone %} </div> <div class="text-center"> <div class="form-group"> <div class="ins-left"> <p>{% render_field form.booked_instrument value=lesson.lesson_instrument %}</p> </div> <div class="date-right"> <p>{% render_field form.booked_date value=lesson.lesson_datetime_start|date %}</p> </div> </div> <br /> <br /> <div class="form-group"> <label>Length</label> {{ form.booked_length }} </div> <br /> <div class="form-group"> <label>Time</label> {{ form.booked_time }} </div> <div class="ins-left"> <p id="price"></p> </div> <div class="bottom"> <button type="submit" name="submit" class="btn blue_button">Book Now</button> </div> </div> </form> β¦ -
django must be installed on server that is located in apache?
When I read django doc, apache config file should be configured as below <Directory /tutorial/django/tutorial/tutorial/> <Files wsgi.py> Require all granted </Files> </Directory> It means django must be installed on the same server running apache. Right? As I know, apache and tomcat can be located on other server. architecture is like below. apache - load balancer -tomcat But Django must be like below? load balancer - apache(+django) If yes, there is any reason ? -
Related Field got invalid lookup: icontains - Django 2.1
I am trying to make the "vanKit" field searchable in my admin page. "vanKit" is a ForeignKey and whenever I add it it my search_fields list it gives me this error "Related Field got invalid lookup: icontains". Here's my code: Models.py class KitSupplies(models.Model): supplyName = models.ForeignKey(supplies, on_delete=models.CASCADE) vanKit = models.ForeignKey(van_kit, on_delete=models.CASCADE) quantity = models.PositiveSmallIntegerField(blank=False) def __str__(self): return str(self.supplyName) class Meta: verbose_name_plural = 'Kit Supplies' admin.py class KitSuppliesAdmin(admin.ModelAdmin): list_display = ('supplyName', 'vanKit', 'quantity') search_fields = ['vanKit'] admin.site.register(KitSupplies, KitSuppliesAdmin) I tried to use search_fields = ['vanKit__name'] like the other stack overflow answers suggested but that did not work for me. Can anyone explain why I am getting this error and how to get around it? I am using Django 2.1 and python 3.7. Thanks in advance! -
Properties of state not setting ["This field is required."]
I have a django/react (s3 bucket for image upload)project which adds recipes to a postgres database. In my RecipeFormContainer Component one of my properties to the recipe is an Array of ingredients. The array is supposed to be filled with objects that are made up of the key value pairs of units, quantity etc. I have written a method called addIngredients, but it does not seem to be adding the objects into my ingredients array. I get the error "ingredients: ["This field is required."]" when trying to submit my recipe and do a post. Please enlighten me with what I am missing. Code is as follows: import React, {Component} from 'react'; import {Form} from 'react-bootstrap' import Button from 'react-bootstrap/Button'; class RecipeFormContainer extends Component { constructor(props) { super(props); this.state = { title: '', creator: '', mealTime: "", prepTime: "", cookTime: "", image_preview: "", servings: "", directions: '', ingredients: [{ units: '', amounts: '', multiples: '', quantity: '', name: '' }], image: "", }; this.handleImage = this.handleImage.bind(this); this.handleIngredientInput = this.handleIngredientInput.bind(this); this.handleAddIngredients = this.handleAddIngredients.bind(this); } handleAddIngredients =(e) => { e.preventDefault(); // the ingredients properties are not being added to the ingredients array property on state ************************* let ingredient = {units: '', amounts: '', β¦ -
alternative to django-crispy-forms
I am developing an application in django 2.1 and using bootstrap 4 which requires a form for the registration of users. In most of the examples I have seen, examples of single-column forms are shown, which is enough for a form with few fields, but for a more complex one it would be ugly since you would have to scroll through the number of fields. For which I wanted to design a form of this type Server side Investigating a bit I found this tutorial Advanced Form Rendering with Django Crispy Forms in which use is made of Django Crispy Forms and you get the form you wanted. However I did not want to use it, so try to do it manually and get to this. I think that it can be improved a little more since it is not so clean, however it is an alternative to reach the same result as using Django Crispy Forms.I think this can be done using ajax but so far I have never used it. He will also ask himself why complicate doing this if someone already did it, well it is a way to understand how everything works without any magic. views.py β¦ -
Django HTML Form Send Attachment Emails
I have the following problem using this import from django.core.mail.message import EmailMessage And my code looks something like this: if request.method == 'POST': email = EmailMessage() email.subject = "Test" email.body = mainMessage email.from_email = "SMTP <XXX@XXX.net>" email.to = [ "XXX@XXX.net" ] email.attach_file(file) email.send() And I check for my file with: if 'file' in request.FILES: file = request.FILES['file'] else: file = False And this is what my HTML looks like <form method="post" action="{% url 'myurl' %}" enctype="multipart/form-data"> {% csrf_token %} <input type="file" name="file" required><br> <input type="submit" name="submit" value="Submit"> </form> If I choose a file, how can I make it to be sent as an attachment with that email? If I remove email.attach_file(file) it works just fine, but only sends the text. -
Django and Nginx set-up doesn't serve static files
My Django-Nginx set up mysteriously stopped serving static files to my site after a reboot. The site seems to be hosting fine, but I am given a '404' error when my site tries to serve CSS files and other static content. "CoolBlog" is the name of the project, 'Blog' is the name of an app. Directory Tree: site.mywebsite.com | βββ database β βββ db.sqlite3 βββ source β βββ blog β βββ CoolBlog β βββ functional_tests.py β βββ manage.py β βββ requirements.txt β βββ static βββ static β βββ admin β βββ bootstrap-4.3.1-dist β βββ css β βββ styles.css βββ virtualenv βββ bin βββ lib Relevant section from CoolBlog/settings.py: STATIC_ROOT = os.path.join(BASE_DIR, '../static') STATIC_URL = '/static/' Sites-Available/site.mywebsite.com: server{ listen 80; server_name site.mywebsite.com; location /source/static { alias /home/elspeth/sites/site.mywebsite.com/static; autoindex on; } location / { proxy_pass http://unix:/tmp/site.mywebsite.com.socket; proxy_set_header Host $host; } } Software/OS versions: Ubuntu 16.04.6 LTS Django 2.1.7 nginx/1.10.3 Gunicorn 19 I'd really appreciate advice about how to proceed. I apologize in advance if the problem is really simple or -
Save model object to 2 users
I have a form that I when submitted I want to save the information to 2 users. My form is not saving to the database, and I am receiving no errors, so I am unsure what the problem is. I have tried altering my view and form, and believe that the problem lies there. I would greatly appreciate any help in helping my form pass as valid, and save to the database. HTML <form action="{% url 'view:book_lesson' lesson.id %}" method="POST" autocomplete="off"> {% csrf_token %} <div class="hidden"> {% load tz %} {% timezone user.time_zone %} <p><span id="start">{{ lesson.lesson_datetime_start|time }}</span></p> <p><span id="end">{{ lesson.lesson_datetime_end|time }}</span></p> {% endtimezone %} </div> <div class="text-center"> <div class="form-group"> <div class="ins-left"> <p>{% render_field form.booked_instrument value=lesson.lesson_instrument %}</p> </div> <div class="date-right"> <p>{% render_field form.booked_date value=lesson.lesson_datetime_start|date %}</p> </div> </div> <br /> <br /> <div class="form-group"> <label>Length</label> {{ form.booked_length }} </div> <br /> <div class="form-group"> <label>Time</label> {{ form.booked_time }} </div> <div class="ins-left"> <p id="price"></p> </div> <div class="bottom"> <button type="submit" name="submit" class="btn blue_button">Book Now</button> </div> </div> </form> models.py class Booked(models.Model): users = models.ManyToManyField(User) booked_instrument = models.CharField(max_length=255, blank=True) booked_length = models.CharField(max_length=255, choices=length_list, blank=True) booked_date = models.DateField(null=True, blank=True) booked_time = models.TimeField(null=True, blank=True) forms.py class BookedForm(forms.ModelForm): booked_instrument = forms.CharField(widget=forms.TextInput(attrs={'class' : 'form-control', 'disabled' : 'True'})) booked_length = forms.ChoiceField(choices=length_list, β¦ -
Realtime monitoring using Django
I want to monitor some network devices using Django. Lets say I have three PC in three different locations. PC1 = city1 PC2= city2 PC3= city3 Something like this: example what is the best way to make a realtime monitoring application in Django. I know already the I can use snmp or ping to get the status of these PC's. (using views). And I know a bit about mapbox of Java to get an interactive map. So! how can I have a webpage that automatically update the status of these PC's for example every 10 seconds? -
List and filtering posts
I am trying to filter my posts based on some privacy setting. Currently my lists are being overwritten and I am not sure why. I tried to append as well as add the items to the individual lists and then after combine all queries into my streamlist to be displayed but that does not work. Also I am not sure how to filter the posts when a GET method is requested that is why I filter by all() for now. This is my views.py public_posts_list = [] private_posts_list = [] friends_posts_list = [] foaf_posts_list = [] server_posts_list = [] only_me_posts_list = [] streamlist = [] if request.method == "POST": form = PostForm(request.POST or None, request.FILES or None) if form.is_valid(): instance = form.save(commit=False) instance.user = request.user instance.publish = datetime.now() instance.save() user = request.user print("Privacy:", instance.privacy) if instance.privacy == 0: public_posts_list = Post.objects.filter_by_public() print("public length: ", len(public_posts_list)) print("Public list: ", public_posts_list) elif instance.privacy == 1: private_posts_list = Post.objects.filter_by_private() print("public length: ", len(private_posts_list)) print("Public list: ", private_posts_list) elif instance.privacy == 2: friends_posts_list = Post.objects.filter_by_friends() print("public length: ", len(friends_posts_list)) print("Public list: ", friends_posts_list) elif instance.privacy == 3: foaf_posts_list = Post.objects.filter_by_foaf() print("public length: ", len(foaf_posts_list)) print("Public list: ", foaf_posts_list) elif instance.privacy == 4: server_posts_list = β¦ -
Having permission problems while trying to create pdf file on Apache Server using Django
I have a problem with deployment of my web app. I am using Django 2.1.7 on apache2. I set all the proper permissions to folders and files (at least thats what I think): drwxr-s--- 10 bedirt www-data 4096 Mar 8 21:10 projectNal And in the folder: -rwxr-x--- 1 bedirt www-data 11357 Mar 2 20:37 LICENSE -rwxr-x--- 1 bedirt www-data 12 Mar 2 20:37 README.md drwxr-x--- 4 bedirt www-data 4096 Mar 2 20:42 addQuestion -rwxrwx--- 1 bedirt www-data 536576 Mar 2 21:51 db.sqlite3 -rwxr-x--- 1 bedirt www-data 542 Mar 2 20:37 manage.py drwxrwx--- 2 bedirt www-data 4096 Mar 8 21:10 media drwxr-x--- 3 bedirt www-data 4096 Mar 8 21:53 projectNal drwxr-x--- 6 bedirt www-data 4096 Mar 8 22:49 qBank -rwxr-x--- 1 bedirt www-data 512 Mar 2 20:37 requirements.txt drwxr-x--- 12 bedirt www-data 4096 Mar 2 20:37 static drwxr-x--- 5 bedirt www-data 4096 Mar 2 20:37 users drwxr-x--- 5 bedirt www-data 4096 Mar 2 20:37 venv I am using pylatex to create a latex document, the procedure is - it runs latex compilation and removes the .tex file, and uploads the pdf on media folder. Here is the code: Output_tex.py def create_worksheet_pdf(data, title): # Document with `\maketitle` command activated doc = Document(default_filepath='../media/', β¦ -
Mqtt django implements
help someone knows or helps me on how to implement mqtt in django rest framework and I'm annoyed to find an answer but my project is not https://github.com/ehooo/django_mqtt -
Django cannot unpack non-iterable 'Q' object
Im trying to use Q to make query in django. Database im using for this class is PostgreSQL. My model is: class DataSetPG(models.Model): tower_code = models.CharField(max_length=20, null=False) time_stamp = models.DateTimeField(default=datetime.now, null=True, blank=True) value = models.CharField(max_length=200) class Meta: ordering = ('tower_code',) def __str__(self): return "%s" % self.tower_code My view is asking for: DataSetPG.objects.filter(Q(tower_code="something")) But i got this error: TypeError: cannot unpack non-iterable Q object What I'm doing wrong? I tried .get instead of .filter and many many other kinds of stuff, but nothing. Im also using Q for querying in mongo database and works fine. -
Mezzanine CMS - User Filter in Blog List/Detail Views
When I create a new blog post in Admin, the post gets created successfully and it's listed in the posts list and I can navigate to the full post by clicking on it in the list. However, when I login using a different user (non-admin) or without login, I don't find this post in the blog posts list and I get 404 when I try to navigate to the post using its slug. So I am trying to make sense of Mezzanine's blog_post_list and blog_post_detail views code: def blog_post_list(request, tag=None, year=None, month=None, username=None, category=None, template="blog/blog_post_list.html", extra_context=None): """ Display a list of blog posts that are filtered by tag, year, month, author or category. Custom templates are checked for using the name ``blog/blog_post_list_XXX.html`` where ``XXX`` is either the category slug or author's username if given. """ templates = [] blog_posts = BlogPost.objects.published(for_user=request.user) if tag is not None: tag = get_object_or_404(Keyword, slug=tag) blog_posts = blog_posts.filter(keywords__keyword=tag) if year is not None: blog_posts = blog_posts.filter(publish_date__year=year) if month is not None: blog_posts = blog_posts.filter(publish_date__month=month) try: month = _(month_name[int(month)]) except IndexError: raise Http404() if category is not None: category = get_object_or_404(BlogCategory, slug=category) blog_posts = blog_posts.filter(categories=category) templates.append(u"blog/blog_post_list_%s.html" % str(category.slug)) author = None if username is not None: β¦ -
Python Django send_mail function
Is there any way to send an attachment with the send_mail() function from Django? And if not, could someone please send me a link to a module that has this possibility. -
Is it possible to program web app using python without "any" framework?
I'm worked on PHP previously and want to know python web programming. But everything for me is ambiguous. Is it possible to program web app using python without "any" framework? I know frameworks make everything easy for us and even if it is possible program web app without framework , it is not logical for big projects. But my target is just learning because I think start programming with frameworks is not good idea and we should know some information about pure python in web applications. So Imagine I want make very very simple webpage like hello world or small counter or small api. please do not offer me lightweight frameworks like flask. I just want know can pure python create webpages? -
call_command return Bad gateway 502 from API
I'm using call_command inside an endpoint: Python 2.7 class TestCrawlerView(views.APIView): permission_classes = (IsAuthenticated, ) def post(self, request): data = request.data try: call_command('berkley_vsales_proposal', verbosity=0, data=data) save_status(data['proposal_hash'], 'success') return Response({"crawler": "success"}) except Exception as error: hash_proposal = data['proposal_hash'] save_status(hash_proposal, error) return Response({"crawler": "error: " + str(error) }) It is calling a crawler, using selenium, till now ok. It works perfectly on my local machine. But when i deploy it to an ubuntu on AWS this endpoint specifically return 502 bad gateway or 504 time out, all other endpoints work. The test If i remove the line call_command from this endpoint, it return 200 ok. So i realize that the problem is this command. But i need it to call crawler. Error only on remote server <html> <head> <title>502 Bad Gateway</title> </head> <body bgcolor="white"> <center> <h1>502 Bad Gateway</h1> </center> <hr> <center>nginx/1.14.0 (Ubuntu)</center> </body> </html> You guys have some try to me? -
Why isn't mobile detection enabled working in my Django template?
I'm using Django and Python 3.7. I would like to display some table data slightly differently on mobile browsers, so I formatted my table view template like so ... {% if request.user_agent.is_mobile %} <td align="center"><a href="{{ articlestat.article.mobile_path }}" target="_blank">{{ articlestat.hits|floatformat:"0" }}</a></td> {% else %} <td align="center"><h2><a href="{{ articlestat.article.path }}" target="_blank">{{ articlestat.hits|floatformat:"0" }}</a></h2></td> {% endif %} However after deploying and restarting my server, viewing this on a mobile browser still shows the non-mobile branch. Is there something else I need to do to activate mobile detection? My phone is an Android LG, viewing on a Chrome browser if that matters. -
Django: foreign key to two models
I'm trying to build a app in Django. Let's say I have this model : class Server(model.Models): hosted_by = models.ForeignKey('Self', limit_choices_to={'backup_server': True}) host = models.BooleanField(default=False) This class defines a server. Each server can be a host, which means it can hosts other servers (virtual). So, Each server can be hosted by an other server. That's easy. But here's the problem : a host can be part of a cluster of hosts. And so, a virtual server can be hosted by a standalone host, or by a cluster. When a server is hosted by a cluster, I don't want to specify by which host in the cluster. I don't know how to manage the "hosted_by". I tried to use Contenttype and generic relations, but it was not user friendly at all in the admin section. I created a new model : class Cluster(models.Model): So my Server is now like this : class Server(model.Models): hosted_by = models.ForeignKey('Cluster' ...) host = models.BooleanField(default=False) member_of_cluster = models.ForeignKey('Cluster' ...) Beside the fact that my Server in linked twice to Cluster (but with related_name it works), now a host can only be linked to a cluster... Is there a easy, simple way to do something like : β¦ -
Django form validation - set default value when field value is empty
I may be undertaking this completely wrong, but I will ask anyway. On an input form, I have a radio button group (3 radio buttons) that a user must select from. I have implemented client side validation to make the user select one of the radio buttons. On the form.py, I currently have the following code to return the user back to the form with an error message if the client side validation fails when the user has not selected a radio button: class PublishedDetailsForm(BaseDetailsForm): .... def published_details_format_val(self): return self.field_val('published_details_format') .... How do I change this code to accept a default value instead of returning the user to the form when the radio button value has not been selected. I want the default value to be the same default value for the models class. I may be wrong, but I am presuming that this would be undertaken in the forms.py file. So I wrote some code below - but this does not work. Here is my relevant forms.py code: from ******* import PublishedDetails from ******* import format_types as display_types class PublishedDetailsForm(BaseDetailsForm): .... class Meta: model = PublishedDetails .... def clean(self): cd_rpdf = super(PublishedDetailsForm, self).clean() if 'published_details_format' in cd_rpdf: if cd_rpdf['published_details_format'] β¦