django-views

My defaultdict(list) won't show up on template but does in my view [duplicate]

不羁的心 提交于 2019-12-01 07:03:17
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Django template can’t loop defaultdict I am wondering why my defaultdict(list) will show when I test it in my views.py but when I go to show the data on my template, I get nothing, not even an error. Any suggestions? Here is my views.py - confirm_list is my defaultdict(list) def confirmations_report(request, *args, **kwargs): from investments.models import Investment, InvestmentManager from reports.forms import

Multiple models generic DetailView to template

落花浮王杯 提交于 2019-12-01 06:23:50
问题 I have 2 models and I got the IndexView working properly using the get_context_data method. However my DetailView using the same technique is not working. How do I simply get 2 models into the DetailView ? views.py from .models import CharacterSeries, CharacterUniverse class IndexView(generic.ListView): template_name = 'character/index.html' context_object_name = 'character_series_list' def get_queryset(self): return CharacterSeries.objects.order_by('name') def get_context_data(self, **kwargs

Django Query distinct values works but i cant use the query result

核能气质少年 提交于 2019-12-01 06:10:51
I have a table column which some values are double or triple written. I want to have a distinct query. I tried staff = Staff.objects.all().values('person').distinct() for k in staff: j = k.person print j,k I get "dict object has not attribute as person" for k.person And I get k gives me a result like {'person': 778L} {'person': 779L} {'person': 780L} {'person': 781L} {'person': 782L}` Do you know how can I get the person value? Its not problem with distinct but with values() . values() gives you dict of values you requested. And to get attribute from dict you can use dict['attr_name'] . So you

DateTimeField queryset returning None in Django

戏子无情 提交于 2019-12-01 05:14:44
I am trying to create a queryset for getting the values of a DateTimeField which is DATETIME in the DB. The class in models.py: class ChangeMetrics(models.Model): id = models.IntegerField(primary_key=True) file_id = models.ForeignKey(File, db_column = 'file_id') version_id = models.ForeignKey(Version, db_column = 'version_id') function_id = models.ForeignKey(Function, blank=True, db_column = 'function_id') date = models.DateTimeField(blank=True, null=True) user = models.TextField(blank=True) changed = models.IntegerField(blank=True, null=True) The field in the DB: date DATETIME The tuples are

Django raising 404 with a message

荒凉一梦 提交于 2019-12-01 04:13:40
I like to raise 404 with some error message at different places in the script eg: Http404("some error msg: %s" %msg) So, in my urls.py I included: handler404 = Custom404.as_view() Can anyone please tell me how should I be handling the error in my views. I'm fairly new to Django, so an example would help a lot. Many thanks in advance. aherok In general, 404 error is "page not found" error - it should not have customizable messages, simply because it should be raised only when a page is not found. You can return a TemplateResponse with status parameter set to 404 Generally there should not be

Django form with many-to-many relationship does not save

谁说胖子不能爱 提交于 2019-12-01 03:40:51
I have a custom registration form for my users to add a profile on my app. However, a bug has recently popped up in that the form is not saving the information that is put into all the fields. My user model, MyUser has a ManyToMany relationship with another model, Interest , and this is where the issues are arising. I am not sure if it is the RegistrationForm or the register view that is causing it, so I have included both below, as well as the model code. I also have a view for the users to update their profile, also included, once it is created, and this is working absolutely perfectly. This

DateTimeField queryset returning None in Django

早过忘川 提交于 2019-12-01 02:40:34
问题 I am trying to create a queryset for getting the values of a DateTimeField which is DATETIME in the DB. The class in models.py: class ChangeMetrics(models.Model): id = models.IntegerField(primary_key=True) file_id = models.ForeignKey(File, db_column = 'file_id') version_id = models.ForeignKey(Version, db_column = 'version_id') function_id = models.ForeignKey(Function, blank=True, db_column = 'function_id') date = models.DateTimeField(blank=True, null=True) user = models.TextField(blank=True)

Django Query distinct values works but i cant use the query result

六月ゝ 毕业季﹏ 提交于 2019-12-01 02:02:23
问题 I have a table column which some values are double or triple written. I want to have a distinct query. I tried staff = Staff.objects.all().values('person').distinct() for k in staff: j = k.person print j,k I get "dict object has not attribute as person" for k.person And I get k gives me a result like {'person': 778L} {'person': 779L} {'person': 780L} {'person': 781L} {'person': 782L}` Do you know how can I get the person value? 回答1: Its not problem with distinct but with values() . values()

django-registration, registration and login form on index page together, did I do it right?

巧了我就是萌 提交于 2019-12-01 01:12:43
I'd appreciate some code review, I used django-registration app and django.contrib.auth module. What I wanted to do is have both the login and registration form on the index page, and manage it from there. What I did is I just copied code from registration.views.py and contrib.auth.views.py and banged it together. It works but I feel it's very hack-ish, non elegant, and that there is another, proper way to do it. For example I feel it might be better to call or extend view methods in registration and auth instead of copy pasting them. def index(request, success_url=None, form_class

Django form with many-to-many relationship does not save

邮差的信 提交于 2019-11-30 23:22:42
问题 I have a custom registration form for my users to add a profile on my app. However, a bug has recently popped up in that the form is not saving the information that is put into all the fields. My user model, MyUser has a ManyToMany relationship with another model, Interest , and this is where the issues are arising. I am not sure if it is the RegistrationForm or the register view that is causing it, so I have included both below, as well as the model code. I also have a view for the users to