django-views

How import a function from another view with Django?

假如想象 提交于 2019-12-24 19:24:13
问题 I have this folder hierarchy: |---- saga |---- core |---- views.py |---- study_time |---- views.py On my study_time/views.py , I have this functions: def study_time(request): def tasks_subjects(week_day, key): #Code here return __tasks def day_studies(week_day): __tasks_subjects = tasks_subjects(week_day, 0) #Code here return __studies return render(request, 'study_time.html', context) On my core/views.py , I need the day_studies() function, so I'm importing like this: from saga.study_time

django get_profile error

萝らか妹 提交于 2019-12-24 19:22:39
问题 I want to get my userprofile id in the views i have already included below in settings.py AUTH_PROFILE_MODULE = 'users.UserProfile' views code: def savecontent(request): try: logging.debug("=========================== in save content") logging.debug(dir(request.user)) my_id = request.user.get_profile().id logging.debug(my_id) Error is: 2012-07-17 13:00:00,564 ERROR Error while saing content Traceback (most recent call last): File "/opt/labs/labs_site/content/views.py", line 21, in savecontent

Django - return all associated rows for distinct results set with postgres backend

China☆狼群 提交于 2019-12-24 18:51:32
问题 I have data in the following form: collection_name | type | manufacturer | description | image_url --------------------------------------------------------------------------- beach | bed | company a | nice bed | 1.jpg beach | king bed | company a | nice bed | 1.jpg beach | nightstand | company a | nice ns | 1.jpg grass | chest | company a | nice chest | 2.jpg apple | chest | company a | nice chest | 3.jpg fiver | chest | company b | good chest | 4.jpg What I need to do, is select all images

django forms - how to update user data from previous comment when user posts a new comment

亡梦爱人 提交于 2019-12-24 18:23:26
问题 I feel like I'm really close, but not quite there yet. Please bear with me as I am very much so in the beginner stages of learning django. I have a feature where users can comment on each blog post. I want to display the total number of comments each user has next to his name. If that user has left 4 comments on 4 different posts, I want it to show "4 total comments" next to his name on each one of his individual comments throughout my website. I have made a model method that I put in my view

Django 1.6: Displaying a particular models Objects in another template

↘锁芯ラ 提交于 2019-12-24 18:15:06
问题 Working on an application were I have a One to Many relationship where I have many Products and a few particular products will be related to only one Website. On my Home page is where I display my listed sites from my Website Model I would like to show products for when the user clicks on anyone of the slugs on my Homepage the are redirected to go into a product page ( another template ) where I have all of the objects related from my Product Model to that particular website to display only.

Django REST Updateview with PUT POST

南笙酒味 提交于 2019-12-24 16:44:14
问题 Within a listview , with many objects, I want to change their value live by javascript, then save them by a POST/PUT http request to the object updateview , searching I've found that it maybe possible with Django REST framework. I've read the Django REST framework manual reference but didn't understand how to set up the UpdateView call: model.py class presetrows(models.Model): progressivo = models.ForeignKey(preset) value = models.BigIntegerField(blank=True, null=True) views.py class

how do you extract data from json using beautifulsoup in django

一笑奈何 提交于 2019-12-24 16:28:44
问题 Good day. I'm facing an issue while trying to extract values from json. First of all my beautifulsoup works very fine in the shell, but not in django. and also what I'm trying to achieve is extracting data from the received json, but with no success. Here's the class in my view doing it: class FetchWeather(generic.TemplateView): template_name = 'forecastApp/pages/weather.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) url = 'http://weather.news24.com

how to include class based views in context_processors in django?

别来无恙 提交于 2019-12-24 16:08:47
问题 I have this code in context_processors.py class ContactFormView(FormView): form_class = ContactForm template_name = "blog/contact.html" success_url = "/contact/" def form_valid(self,form): contact_name = form.cleaned_data.get('contact_name') contact_email = form.cleaned_data.get('contact_email') form_content = form.cleaned_data.get('content','') try: send_mail(contact_name,form_content,contact_email,[settings.EMAIL_HOST_USER], fail_silently=False) except BadHeaderError: return HttpResponse(

Only last label input value being returned in Django

馋奶兔 提交于 2019-12-24 15:51:57
问题 I am pretty new in Django and I guess there is something I am overlooking. I have a form that I am populating dynamically as shown below <form method="post"> {% csrf_token %} {{ profile.days }}//Only prints last radio button value {% for period, value in profile.periods.items %} <h2>{{ period }} Reports</h2> <label> <input name="days" value={{ value }} type="hidden"> <input name="reports_allowed" type="radio" {% if profile.reports_allowed and profile.days == value %} checked {% endif %}> Each

FormWizard: How to proceed from step 1 to Step 2 when having own 2 templates

 ̄綄美尐妖づ 提交于 2019-12-24 14:12:21
问题 I have 2 steps in formwizard. the first step is where the customer filled up their particular and the second step is about building particular. models.py class customer(models.Model): LAST_NAME = models.CharField(max_length = 50) FIRST_NAME = models.CharField(max_length = 50) ADDRESS = models.CharField(max_length = 60, blank =True) def __unicode__(self): return '{0}' % (self) class building(models.Model): CUSTOMER = models.ForeignKey(customer, null = True, blank = True) BUILDING_USE = models