django-views

Manager isn't accessible via “model” instances django

六月ゝ 毕业季﹏ 提交于 2019-12-25 02:16:17
问题 I am suffering an error with django and their custom Managers. I have this custom Manager: class CallManager(models.Manager): def get_queryset(self): return super(CallManager, self).get_queryset().filter(is_active=True) class Call(models.Model): ... # Data is_active = models.BooleanField(default=True) # Managers objects = models.Manager() # Default active = CallManager() # Active calls Ok, So now I am trying to retrive data from views.py (call/views.py) # Call list def call_list(request):

How to get data from last 48 hours - Django

╄→гoц情女王★ 提交于 2019-12-25 01:49:33
问题 I'm building a news website.I need display 48 hours most viewed news. So I need first to get the 48 hours news, and then get its pv. Currently I'm using a very complicated method which is from a tutorial: def get_two_days_read_data(content_type): today = timezone.now().date() dates = [] read_nums = [] for i in range(2, 0, -1): date = today - datetime.timedelta(days=i) dates.append(date.strftime('%m/%d')) read_details = ReadDetail.objects.filter(content_type=content_type, date=date) result =

Why doesn't multiple inheritance work in Django views?

浪子不回头ぞ 提交于 2019-12-25 01:28:49
问题 I am trying to avoid repeating the list of fields and model specifier in both a form and a (class based) view. This answer suggested defining a "meta class" that has the field list in it, and inheriting that class in both the form and the view. It works fine for the form, but the following code inheriting the list and target model into the view results in this error: TemplateResponseMixin requires either a definition of 'template_name' or an implementation of 'get_template_names()' I'm at a

all forms are not saving to my database using class based views

流过昼夜 提交于 2019-12-25 00:16:53
问题 I have an orderform that is not saving the items ordered to the database. I am only getting the contact form saved. I have searched and can't find what I am doing wrong or missing in my views. Any help would be greatly appreciated. Thank you! Views: class OrderFormView(CreateView): model = Contact form_class = ContactForm template_name = 'orderform.html' success_url = 'thank-you' def get_context_data(self, **kwargs): context = super(OrderFormView, self).get_context_data(**kwargs) formsets =

How to render different data to the same page by two different views - Django

安稳与你 提交于 2019-12-24 23:31:07
问题 I'm building a news website.I need display 48 hours most viewed news, this part is in the detail.html page. Now I'm using this method. def newsDetailView(request, news_pk): news = get_object_or_404(News, id=news_pk) News.objects.filter(id=news_pk).update(pv=F('pv') + 1) time_period = datetime.now() - timedelta(hours=48) host_news=news.objects.filter(date_created__gte=time_period).order_by('-pv')[:7] return render(request, "news_detail.html", { 'news': news, 'host_news' : host_news }) It works

Multiple PDF file should upload,along with pdf file selected client and process should dispalay

[亡魂溺海] 提交于 2019-12-24 21:34:52
问题 Uploaded pdf file is showing correctly but selected client is not showing,Client will displayed in dropdown,if we select particular client and upload multiple pdf files,the selected client and files should display. models.py class Client_files(models.Model): Date = models.DateTimeField(default=datetime.now, blank=True) client = models.ForeignKey(Client, on_delete=models.CASCADE,null=True) client_process = models.ForeignKey(Client_Process, on_delete=models.CASCADE,null=True) File_Name = models

How to save the users last logout time

爷,独闯天下 提交于 2019-12-24 21:24:58
问题 I am looking to save the users last logout time.My idea was to add it to the users profile model. I am using Django 1.11.15 Example: class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) ... last_logout = models.DateTimeField(blank=True, null=True) below is how I created my profile model just for reference def signup(request): if request.method == 'POST': form = UserCreateForm(request.POST or None) if form.is_valid(): new_user = form.save() Profile.objects

Form errors not displaying in UpdateView

[亡魂溺海] 提交于 2019-12-24 20:32:22
问题 I have an UpdateView that will display a form to either create the user profile or update the user profile. It works well, however, for some reason I can't get it to show the form errors. There should be form errors based on the ValidationErrors I have put in the model form. I suspect my views.py to be the cause of the form not displaying the errors. Here's my view: class ProfileSettings(UpdateView): model = Profile template_name = 'profile/settings.html' form_class = ProfileForm success_url

ModelChoiceField invalid literal for int() with base 10: ''

醉酒当歌 提交于 2019-12-24 20:29:31
问题 So I've spent the day trying to chase down a custom thing that I wanted to achieve using FormView. When I use FormView with HTML form method="POST", I am able to get the desired result, mostly. If a user clicks to submit a form and an empty field exists, they get an error message telling them the form is required. I'm aware that I can make the ModelChoiceField required on the form, but was trying to implement my own logic for this. I found through my searching that if I'm not updating

display sum per user elegantly in django

谁都会走 提交于 2019-12-24 19:42:53
问题 trying to display the final mark per student. But instead of just showing the result of sum , it displays a chunk of query set: for example: Annie <QuerySet [{'studName': None, 'attendance__sum': 3}, {'studName': 1, 'attendance__sum': 2}, {'studName': 2, 'attendance__sum': 1}]> and same goes to the rest of the students. I would like to display it like : Annie 2 Benny 3 Charlie 4 My view: def attStudName(request): studentName = MarkAtt.objects.all() mark = MarkAtt.objects.values('studName')