django-views

django - How to copy actual image file from one model to another?

♀尐吖头ヾ 提交于 2020-06-25 22:49:10
问题 I want to copy images from one model to another within the project. Suppose these are my models: class BackgroundImage(models.Model): user = models.ForeignKey(User) image = models.ImageField(upload_to=get_upload_file_name) caption = models.CharField(max_length=200) pub_date = models.DateTimeField(default=datetime.now) class ProfilePicture(models.Model): user = models.ForeignKey(User) image = models.ImageField(upload_to=get_upload_file_name) caption = models.CharField(max_length=200) pub_date

django - How to copy actual image file from one model to another?

落爺英雄遲暮 提交于 2020-06-25 22:49:06
问题 I want to copy images from one model to another within the project. Suppose these are my models: class BackgroundImage(models.Model): user = models.ForeignKey(User) image = models.ImageField(upload_to=get_upload_file_name) caption = models.CharField(max_length=200) pub_date = models.DateTimeField(default=datetime.now) class ProfilePicture(models.Model): user = models.ForeignKey(User) image = models.ImageField(upload_to=get_upload_file_name) caption = models.CharField(max_length=200) pub_date

pass multiple objects to RequestContext in django

不问归期 提交于 2020-06-25 21:34:55
问题 I need to pass a dict and an object to a template. So, I do this rc = RequestContext(request, {'prob':prob}, {'result':result}) return render_to_response('subject/question.html', context_instance=rc) But I get a error. Traceback: File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response 111. response = callback(request, *callback_args, **callback_kwargs) File "E:\django-sample\proschools\..\proschools\subject\views.py" in eval_c 72. rc = RequestContext(request, {'prob'

How to disable intermediate signout page in Django allauth

笑着哭i 提交于 2020-06-24 20:52:31
问题 How to disable the intermediate signout page from django allauth. When the user clicks on the signout link on my site I want him to logout right away, I want to remove this intermediate page 回答1: Set ACCOUNT_LOGOUT_ON_GET to True in your settings. Also see the documentation 回答2: Updated for December 2018. Using a GET request is probably a bad idea due to browsers prefetching urls from the URL bar. Chrome (as of right now) is pretty bad for this; it'll send a GET request to pages it think you

How to disable intermediate signout page in Django allauth

此生再无相见时 提交于 2020-06-24 20:50:27
问题 How to disable the intermediate signout page from django allauth. When the user clicks on the signout link on my site I want him to logout right away, I want to remove this intermediate page 回答1: Set ACCOUNT_LOGOUT_ON_GET to True in your settings. Also see the documentation 回答2: Updated for December 2018. Using a GET request is probably a bad idea due to browsers prefetching urls from the URL bar. Chrome (as of right now) is pretty bad for this; it'll send a GET request to pages it think you

Django - CheckboxSelectMultiple shows object representation instead of object's name

放肆的年华 提交于 2020-06-18 11:25:55
问题 So I am trying to have a list of checkboxes of cities, but instead of showing the cities' name, it shows this: How to make it shows the name instead of City object ? 回答1: In your model you have to include __str__ for python3 and unicode for python 2 For example python 3: class City(models.Model): name = forms.CharField(max_length=200, default="") def __str__(self): return self.name Python 2 class City(models.Model): name = forms.CharField(max_length=200, default="") def __unicode__(self):

Django - CheckboxSelectMultiple shows object representation instead of object's name

末鹿安然 提交于 2020-06-18 11:24:31
问题 So I am trying to have a list of checkboxes of cities, but instead of showing the cities' name, it shows this: How to make it shows the name instead of City object ? 回答1: In your model you have to include __str__ for python3 and unicode for python 2 For example python 3: class City(models.Model): name = forms.CharField(max_length=200, default="") def __str__(self): return self.name Python 2 class City(models.Model): name = forms.CharField(max_length=200, default="") def __unicode__(self):

Django - CheckboxSelectMultiple shows object representation instead of object's name

情到浓时终转凉″ 提交于 2020-06-18 11:23:45
问题 So I am trying to have a list of checkboxes of cities, but instead of showing the cities' name, it shows this: How to make it shows the name instead of City object ? 回答1: In your model you have to include __str__ for python3 and unicode for python 2 For example python 3: class City(models.Model): name = forms.CharField(max_length=200, default="") def __str__(self): return self.name Python 2 class City(models.Model): name = forms.CharField(max_length=200, default="") def __unicode__(self):

Django - CheckboxSelectMultiple shows object representation instead of object's name

狂风中的少年 提交于 2020-06-18 11:22:06
问题 So I am trying to have a list of checkboxes of cities, but instead of showing the cities' name, it shows this: How to make it shows the name instead of City object ? 回答1: In your model you have to include __str__ for python3 and unicode for python 2 For example python 3: class City(models.Model): name = forms.CharField(max_length=200, default="") def __str__(self): return self.name Python 2 class City(models.Model): name = forms.CharField(max_length=200, default="") def __unicode__(self):

How to edit user's profile page on django?

℡╲_俬逩灬. 提交于 2020-06-17 08:05:31
问题 My django project has multiple functions, one of them lets the user update its profile(User model"first_name, username and email" Profile model" bio and profile picture") this used to perfectly work until I added a follow sistem, it is like the whole Profile and User model doesnt exist anymore so when trying to edit those fields, the code returns a AttributeError: 'User' object has no attribute 'profile' error, saying this line of code on the views.py file is wrong form1 = UpdateProfileForm