django-forms

How to style a django form - bootstrap

混江龙づ霸主 提交于 2019-12-20 09:25:09
问题 I am styling my django app but Iam having trouble styling the forms. I have a contact form, in my forms.py and then I have use it in a template. <form class="form-contact" action="" method="POST"> {% csrf_token %} <input type="text" name="Name" id="id_name" value="{{form.name}}" /> <input type="submit" value="Submit" class="btn btn-primary"> </form> That isn't working. I have also tried this, but still no luck, it shows styled fields but doesn't retrieve the information ( I get a message

Returning form errors for AJAX request in Django

为君一笑 提交于 2019-12-20 09:09:04
问题 I've been finding my way around Django and jQuery. I've built a basic form in Django. On clicking submit, I'm using jQuery to make an AJAX request to the sever to post my data. This bit seems to work fine and I've managed to save the data. Django returns a ValidationError when a form is invalid. Could anyone tell me how to return this set of error messages as a response to my AJAX request so I can easily iterate through it using JS and do whatever? I found this snippet. Looking at the JS bit

Create empty queryset by default in django form fields

廉价感情. 提交于 2019-12-20 08:19:38
问题 I have this fields in form: city = forms.ModelChoiceField(label="city", queryset=MyCity.objects.all()) district = forms.ModelChoiceField(label="district", queryset=MyDistrict.objects.all()) area = forms.ModelChoiceField(label="area", queryset=MyArea.objects.all()) district comes from click on city and area comes from click on area. With queryset=MyDistrict.objects.all() and queryset=MyArea.objects.all() form will be very heavy. How can I make querysets empty by default? 回答1: You can have an

Django does not add attribute to the custom ModelForm widget

こ雲淡風輕ζ 提交于 2019-12-20 07:29:19
问题 models.py class MyModel(models.Model): pub_date = models.DateTimeField(default=timezone.now) title = models.CharField(max_length=255, blank=False, null=False) text = models.TextField(blank=True, null=True) forms.py class MyModelForm(ModelForm): tos = BooleanField() class Meta: model = models.MyModel fields = ['title', 'text', 'tos'] widgets = { 'title': TextInput(attrs={'class': 'form-control', 'placeholder': 'Title'}), 'text': Textarea(attrs={'class': 'form-control', 'placeholder': 'Text'}),

form wizard initial data for edit not loading properly in Django?

☆樱花仙子☆ 提交于 2019-12-20 07:20:03
问题 I have a three page form-list coming out of a single model. I could save the model first time, but when I want to edit the model, only the first form shows the initial value, subsequent forms does not show the initial data. but when I print the initial_dict from views, I can see all the initial views correctly. I followed this blog on form wizard. Here is my model.py: class Item(models.Model): user=models.ForeignKey(User) price=models.DecimalField(max_digits=8,decimal_places=2) image=models

Django - how can I make a cell in a table in the admin *changelist* interface editable only if it is null?

孤者浪人 提交于 2019-12-20 07:08:28
问题 I would like my data to be editable inline in the Django admin page. However, I only want some fields columns in each row to be editable. These columns will change for each row. Basically, I want a dropdown choice to be displayed if the value in a certain cell is null. If it is not null, then I don't want it to be editable and would like it to be readonly. models.py : class Size(models.Model): size = models.CharField(max_length=20, primary_key=True) class Book(models.Model): title = models

Limit values in the modelformset field

♀尐吖头ヾ 提交于 2019-12-20 06:46:02
问题 I've been trying to solve this problem for a couple of days now, getting quite desperate. See the commented out code snippets for some of the things I've tried but didn't work. Problem: How can I limit the values in the category field of the IngredientForm to only those belonging to the currently logged in user? views.py @login_required def apphome(request): IngrFormSet = modelformset_factory(Ingredient, extra=1, fields=('name', 'category')) # Attempt #1 (not working; error:

get_success_url() takes exactly 3 arguments (2 given)

泪湿孤枕 提交于 2019-12-20 06:37:27
问题 every one ,, I am using django-registration-redux (1.4) for my django registration(django 1.8),,however ,,when never I registered the web will show the error ,,but the views.py in form_valid, line 43 it is the editing function,,it seems not about the register?? views.py @login_required def edit_thing(request, slug): # grab the object... thing = ProductsTbl.objects.get(slug=slug) if thing.user != request.user: raise Http404 # set the form we're using... form_class = ProductsTblForm if request

How to configure django-uploadify for videos upload only?

天大地大妈咪最大 提交于 2019-12-20 06:28:53
问题 I want to use django-uploadify to upload for videos only, I just want it to upload videos only, all kind of videos, or at least all kind of popular video formats. So far, i added uploadify in settings.py and in urls.py I added this (r'^uploadify/',include('uploadify.urls')), But didn't go through every step described in the docs just yet, I'll do the other steps when you tell me how to configure django-uploadify for videos only. django-uploadify is not well documented so i'm relying on your

Django Ajax Form submit wrongly redirect to another page

半城伤御伤魂 提交于 2019-12-20 06:28:23
问题 When I use ajax to submit a comment form in Django,the page will redirect to a blank page shows me the success data: {"status":"success", "msg":"添加成功"} ,but not stay in current page.I want the page stay in current page and show me the new comment. Here is my update_comment view: def update_comment(request, news_pk): news = get_object_or_404(News, id=news_pk) comment_form = CommentForm(request.POST or None) if request.method == 'POST' and comment_form.is_valid(): if not request.user.is