django-models

Not able to update an item in Django

大兔子大兔子 提交于 2021-01-07 01:46:13
问题 I am trying to update the Bar Information for users by getting their details and setting the Bar instance. But every time I click on the link on my dashboard it redirects me to the dashboard which is what I used for the else statement if it is not a post method. view.py def UpdateUserBar(request): user = request.user.id bar = Bar.objects.get(user_id=user) form = UpdateBar(instance=bar) if request.method == 'POST': form = UpdateBar(request.POST,request.FILES, instance=bar) if form.is_valid():

Not able to update an item in Django

孤街浪徒 提交于 2021-01-07 01:43:48
问题 I am trying to update the Bar Information for users by getting their details and setting the Bar instance. But every time I click on the link on my dashboard it redirects me to the dashboard which is what I used for the else statement if it is not a post method. view.py def UpdateUserBar(request): user = request.user.id bar = Bar.objects.get(user_id=user) form = UpdateBar(instance=bar) if request.method == 'POST': form = UpdateBar(request.POST,request.FILES, instance=bar) if form.is_valid():

models.E006 in abstract parent model - Django 3.1

梦想的初衷 提交于 2021-01-05 11:23:27
问题 I have an abstract model and a few other classes that inherit from it. # models.py class Parameter(models.Model): data = integer = models.IntegerField(blank=True, null=True) class Meta: abstract = True class Temperature(Parameter): received_timestamp = models.DateTimeField(default=datetime.now, blank=True) class Ph(Parameter): received_timestamp = models.DateTimeField(default=datetime.now, blank=True) although my Parameter class is abstract, I get models.E006 error in python manage.py

How to post OneToOne field in django rest-framework using overwrite create method

落爺英雄遲暮 提交于 2021-01-05 07:31:15
问题 I am trying to override create method to make a post request but i am stuck, here is my code class Order(models.Model): street_number = models.PositiveIntegerField(blank=True, null=True) street_name = models.CharField(max_length=250, null=True, blank=True) class Seller(models.Model): order = models.OneToOneField(Order, on_delete=models.CASCADE, related_name='seller_order',blank=True, null=True) first_name = models.CharField(max_length=250, null=True, blank=True) last_name = models.CharField

Django admin returns 404 with tinymce

混江龙づ霸主 提交于 2021-01-05 07:28:34
问题 I'm getting 404 with Django admin and tinymce settings.py STATIC_URL = '/static/' STATICFILES_DIRS= [os.path.join(BASE_DIR, 'static'), ] admin.py @admin.register(Blogpost) class BlogpostAdmin(admin.ModelAdmin): class Media: js = ('blog/tiny.js',) js var script = document.createElement('script'); script.type = 'text/javascript'; script.src = "https://cdn.tiny.cloud/1/no-api-key/tinymce/5/tinymce.min.js"; document.head.appendChild(script); script.onload=function () { tinymce.init( { selector: '

Django admin returns 404 with tinymce

走远了吗. 提交于 2021-01-05 07:25:25
问题 I'm getting 404 with Django admin and tinymce settings.py STATIC_URL = '/static/' STATICFILES_DIRS= [os.path.join(BASE_DIR, 'static'), ] admin.py @admin.register(Blogpost) class BlogpostAdmin(admin.ModelAdmin): class Media: js = ('blog/tiny.js',) js var script = document.createElement('script'); script.type = 'text/javascript'; script.src = "https://cdn.tiny.cloud/1/no-api-key/tinymce/5/tinymce.min.js"; document.head.appendChild(script); script.onload=function () { tinymce.init( { selector: '

How to post OneToOne field in django rest-framework using overwrite create method

允我心安 提交于 2021-01-05 07:24:24
问题 I am trying to override create method to make a post request but i am stuck, here is my code class Order(models.Model): street_number = models.PositiveIntegerField(blank=True, null=True) street_name = models.CharField(max_length=250, null=True, blank=True) class Seller(models.Model): order = models.OneToOneField(Order, on_delete=models.CASCADE, related_name='seller_order',blank=True, null=True) first_name = models.CharField(max_length=250, null=True, blank=True) last_name = models.CharField

'module' object is not iterable when running django website to the server

不想你离开。 提交于 2021-01-04 12:31:45
问题 i wanted to run my django website to their server so i open cmd and go to manage.py directory : C:\Users\computer house>cd desktop/newproject then i type this code : python manage.py runserver but i got this error : Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x03BE5A08> Traceback (most recent call last): File "C:\Users\computer house\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\urls\resolvers.py", line 542, in url_patterns iter

'module' object is not iterable when running django website to the server

℡╲_俬逩灬. 提交于 2021-01-04 12:31:32
问题 i wanted to run my django website to their server so i open cmd and go to manage.py directory : C:\Users\computer house>cd desktop/newproject then i type this code : python manage.py runserver but i got this error : Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x03BE5A08> Traceback (most recent call last): File "C:\Users\computer house\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\urls\resolvers.py", line 542, in url_patterns iter

Annotate Total Count of Descents of Mptt Model

為{幸葍}努か 提交于 2021-01-04 06:41:05
问题 Question Given the models below, I want to get a queryset of all pages, annotated with the total number of comments in the thread associated to the page, including all comments in a comment thread tree associated with pages. I am using django-mptt to store comment tree. I can get this in python using comment.get_descendant_count() , but this is very ineficient when querying all pages Models class CommentThread(models.Model): ... class Page(models.Model): ... thread = models.ForeignKey(