django-views

How to use Django-ratings with bootstrap-rating-input

谁说我不能喝 提交于 2019-12-11 22:16:35
问题 Here goes another star rating question. I want to use bootstrap-rating-input to input rating value (1 to 5) and have django-ratings save the rating to the database. Although I'm a little green with javascript, I really want users to be able to vote using star rating instead of a number input form. Could you show me how to hook up these two apps to make them play nice with each other? What does the view and templates look like? And how do I configure the javascript to make the whole thing work

Django generic login view return 'str object not callable' error

纵然是瞬间 提交于 2019-12-11 20:27:54
问题 My urls.py in myProject is from django.conf.urls import patterns, include, url from testapp import urls urlpatterns = patterns('', url(r'^', include(urls)), ) and my urls.py in myApp (called testapp) is from django.conf.urls import patterns, include, url from testapp.forms import UsersForm urlpatterns = patterns('', url(r'^$', 'django.contrib.auth.views.login', {'template_name': 'testapp/templates/login.html', 'authentication_form':'UsersForm'}), ) My myProject/templates/login.html is <form

Django App Not Communicating with JavaScript Code Block

穿精又带淫゛_ 提交于 2019-12-11 20:14:33
问题 I have a Django application that accepts an Elasticsearch query in a form and produces a downloadable report. An earlier iteration worked great, but we decided to add a component that checks every ten seconds if the report is done being created. Our ultimate goal is to have it check repeatedly for the completed report (and tell the user the report is still processing if not complete), and then either add a button to download the report or just have it automatically begin downloading. However,

Can we format as to how the Model Form displays in Django on template

喜你入骨 提交于 2019-12-11 19:44:58
问题 So I am using the django user model (from django.contrib.auth.models import User) and created a Model Form by using the ModelForm (from django.forms import ModelForm). When i display it on the template it shows up on the select boxes as usernames. i want to display it is first_name and last_name. Thisis the code I am using for form in HTML <form class="form-horizontal" method="post" role="form"> {% csrf_token %} <fieldset> <legend>{{ title }}</legend> {% for field in form %} {% if field

How to incorporate Reportlab with Django Class Based View?

走远了吗. 提交于 2019-12-11 18:45:39
问题 I am trying to convert my HTML to a PDF. I watched this tutorial, https://www.codingforentrepreneurs.com/blog/html-template-to-pdf-in-django/ and I was able to successfully get the tutorial to work with hardcoded values. The problem is...I can't figure out how to dynamically incorporate my model and it's attributes into this example. Here are the steps I followed... First I installed reportlab into my environment with the following version... pip install --pre xhtml2pdf This worked... Then I

Get count on filtered subqueries in template

风流意气都作罢 提交于 2019-12-11 18:44:58
问题 If I have a parent model and a child model, how can I then list all child objects of a parent object, and have a filtered count for each child object, when listing them? To give an example, assume we have these models: class Category(models.Model): ... class SubCategory(models.Model): category = models.ForeignKey(Category) .... class Tag(models.Model): .... class Article(models.Model) sub_category = models.ForeignKey(SubCategory) tag = models.ForeignKey(Tag) Then we have a DetailView for a

Django how to iterate querysets of two subclasses in template?

此生再无相见时 提交于 2019-12-11 18:29:43
问题 I am using django-model-utils for inheritance Managers. I want to get result of both sub-classes with one dictionary without getting duplicates. models.py class Images(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='images_created', on_delete=models.CASCADE) created = models.DateTimeField(auto_now_add=True, null=True, blank=True) objects = InheritanceManager() class Postimg(Images): user_img= models.ImageField(upload_to='images/%Y/%m/%d', null=True, blank=True)

Simple Django form in Twitter-Bootstrap modal

妖精的绣舞 提交于 2019-12-11 18:28:58
问题 I'm trying to run django forms with Twitter-Bootstrap modals. I'd like to know what should I do to return to / after form submission. My views and templates are below. url.py urlpatterns = patterns('myapp.views', url(r'^$', 'main'), url(r'^add/', 'form_add'), ) views.py def main(request): if request.method == 'POST': form = MyModelForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] request.session['name'] = name mm = MyModel.objects.create(name=name) mm.save() return

Custom Formset :- Assigning foreign key value and inputting a field only once [ Logged in User ]

∥☆過路亽.° 提交于 2019-12-11 18:25:49
问题 I have a modelformset to populate the timetable model. Models class Timetable(models.Model): day = models.ForeignKey('Day',on_delete=models.CASCADE) start = models.IntegerField() end = models.IntegerField() period = models.CharField(max_length=12) classteacher = models.ForeignKey('Class_teacher',on_delete=models.SET_NULL) class Class_teacher(models.Model): first_name = models.CharField(max_length=200) last_name = models.CharField(max_length=200) empid = models.CharField(max_length=10) email =

Associating a model with another model when saving it

a 夏天 提交于 2019-12-11 18:14:14
问题 I have the following code. The product is like this: There's a book list. On each book item is a form. This form saves a post and makes it related to this particular book. When you click a book item, you see a list of posts, all related to this book item. So far the book list works fine, saving post data works fine, and when you click a list, it (the DetailView) shows the list of posts (instead of book description, which is usually how DetailView is used) fine. What's not working is saving