Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Add related objects to inline
I have a OneToOneField with my User and UserProfile model. And a second model transaction. When a transaction is created it takes a foreignKey User object. What I'd like is with the OneToOneField UserProfile to display the transaction objects related to that user. With the str representation of the transaction object. So that it will look like this: class transaction(models.Model): amount = models.IntegerField() investment_point = models.ForeignKey(investment_point, on_delete=models.CASCADE) user = models.ForeignKey(User, on_delete=models.CASCADE) class UserProfile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) ip = models.IntegerField(default=0) ingameName = models.CharField(max_length=50, default='NotSet') def create_user_profile(sender, instance, created, **kwargs): if created: UserProfile.objects.create(user=instance) post_save.connect(create_user_profile, sender=User) And in my admin panel class UserProfileInline(admin.StackedInline): model = UserProfile can_delete = False verbose_name_plural = 'profile' class UserAdmin(UserAdmin): inlines = (UserProfileInline, ) admin.site.unregister(User) admin.site.register(User, UserAdmin) -
model.objects.create in views is not working in my django project?
This is models.py from django.db import models class Iot(models.Model): user = models.CharField(max_length="50") email = models.EmailField() This is my views.py def Test(request): if request.method == 'PUT': user = request.data['user'] email = request.data['email'] try: s = Iot.objects.create(user=user) print s.user s.email = email s.save() return Response('ok', status=status.HTTP_200_OK) except: return Response('error',status=status.HTTP_400_BAD_REQUEST) I'm using django rest_framework. When i send data it does not store in database and returns: ('error',status=status.HTTP_400_BAD_REQUEST) -
Filter on "larger than 0.01" in Django DecimalField or FloatField
The table model may look something like this: def product(models.Model): price = models.DecimalField(max_digits=20, decimal_places=4, default=Decimal('0.0500')) alt_price = models.FloatField(default=0.05) The query something like: p = Product.objects.filter(price__lt=Decimal('0.01')) or: p = Product.objects.filter(alt_price__lt=0.01) Unfortunately neither works for me. I have plenty of products that fit the requirement. Querying in MySQL does work fine... Where am I going wrong? -
Change Django site display name using the manage.py shell?
I have a django application where its site domain name is example.com. How can I change its Display name using the manage.py shell? I been looking thorough the “sites” framework for a method but I cannot find anything -
Django Rest Framework - realization of wiki pages management
Tell me how I should realize following task (I do not ask you to write code, but rather to explain models structure, relations). WiKi page has two fields: title, text. There may be other fields at the discretion of developer. When editing the page, new version is created, but old version is saved. After editing, new version becomes "current". The administrator makes decision which version is "current". API has to support the methods: to get list of all pages to get list of versions of one page to get any version of one page to get "current" version of the page to edit page method for doing any page "current" -
download txt file automatically from django
In the following code, if i change the file output format to output.csv the file gets automatically downloaded ,but if i change the format to output.txt the files gets displayed on the browser.How to auto download the output.txt file def downloadcsv(request): try: response['status'] = 0 response = {} output = fq_name+"/"+ "output.txt" os.system(cmd) logger.debug(file_name) response.update({'status':0,'message': 'Success','file_name' : output}) except Exception as e: response['message'] = "Exception while processing request" response['status'] = 2 logger.exception(e) return HttpResponse(JsonResponse(response), content_type="application/json") $.post("/reports/downloadcsv/", snddata, function callbackHandler(data, textstatus) { if (data.status == 0) { document.location.href = data.file_name; //document.getElementById('my_iframe').src = data.file_name; } else if (data.status == 1 || data.status == 2) { $('#loading').hide(); alert('Error while processing data'); } $('#loading').hide(); }, "json" ); -
Got mod_wsgi unable to connect WSGI daemon process?
I used Easy apache 4,mod_wsgi and python 3.5 when i called an django project in the server i got the following error.I am a newbie, any solutions can be appreciated. (13)Permission denied: mod_wsgi (pid=24223): Unable to connect to WSGI daemon process 'user123' on '/var/run/wsgi.8442.6.7.sock' as user with uid=3708. -
Serializer.is_valid() raises Queryset error while serializer.is_valid(raise_exception=True) does not
The issue here is easy to fix and the reason I open it is that I don't understand what's happening. Here's the code from django-rest-auth: class PasswordResetView(GenericAPIView): """ Calls Django Auth PasswordResetForm save method. Accepts the following POST parameters: email Returns the success/fail message. """ serializer_class = PasswordResetSerializer permission_classes = (AllowAny,) def post(self, request, *args, **kwargs): # Create a serializer with request.data serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) serializer.save() # Return the success message with OK HTTP status return Response( {"success": _("Password reset e-mail has been sent.")}, status=status.HTTP_200_OK ) It's the whole class and it surely works well. I make a copy with a small change - instead of serializer.is_valid(raise_exception=True) I expand it: if serializer.is_valid(): serializer.save() # Return the success message with OK HTTP status return Response( {"success": _("Password reset e-mail has been sent.")}, status=status.HTTP_200_OK ) else: return Response( {"error": "Something's wrong."}, status=status.HTTP_400_BAD_REQUEST ) When I run it I get AssertionError: 'PasswordResetView' should either include a queryset attribute, or override the get_queryset() method. The only difference is in using serializer.is_valid(raise_exception=True) (Ok) or just serializer.is_valid() (fail). Can somebody explain it to me? It's not the first time I see such an issue. Of course I can write an empty def get_quesryset(): return None … -
Installing Github dependencies in Django
I just got started with Django and as far as I understand dependencies are managed through the requirements.txt file. I assume they're not automatically pulled so I ran pip to install them. pip install -r requirements.txt (after cding into the appropriate directory) However there are some requirements hosted in Github with the following format: git+https://github.com/user/project.git When pip install -r gets to any of these lines I am getting an error: Cannot find command 'git'. I am not sure how to deal with this. I am on Windows and using PyCharm. The project I'm working on has git configured however when running git from the PyCharm terminal the command isn't found. Could this be the problem? How can I solve this? -
Need text within tag including tags
I Have my HTML like below. <td>meter/second<font class="font103148"><sup>2</sup></font></td> I need Output like : meter/second<font class="font103148"><sup>2</sup></font> using BeautifulSoup. I have tried using regular expression: r = re.findall('def(.*?)end', doc) Unable to get proper output -
Django: Test an Abstract Model
I have a simple abstract class and I want to write a unit test for this. I am using Django 1.10 and the most answers I have found are out there for years and maybe are outdated. I have tried the solution from Vinod Kurup: # tests/test_foo.py from django.db import models from django.test import TestCase from ..models import MyAbstractModel class MyTestModel(MyAbstractModel): name = models.CharField(max_length=20) class Meta: app_label = 'myappname' class AbstractTest(TestCase): def test_my_test_model(self): self.assertTrue(MyTestModel.objects.create(name='foo')) But this just give me an error: Traceback (most recent call last): File "/home/arch/.environments/djanveg_dev/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) psycopg2.ProgrammingError: relation "recipes_flagstestmodel" does not exist LINE 1: ..."."deleted", "recipes_flagstestmodel"."name" FROM "recipes_f... ^ The above exception was the direct cause of the following exception: Traceback (most recent call last): File "manage.py", line 22, in <module> execute_from_command_line(sys.argv) File "/home/arch/.environments/djanveg_dev/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line utility.execute() File "/home/arch/.environments/djanveg_dev/lib/python3.5/site-packages/django/core/management/__init__.py", line 359, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/arch/.environments/djanveg_dev/lib/python3.5/site-packages/django/core/management/commands/test.py", line 29, in run_from_argv super(Command, self).run_from_argv(argv) File "/home/arch/.environments/djanveg_dev/lib/python3.5/site-packages/django/core/management/base.py", line 305, in run_from_argv self.execute(*args, **cmd_options) File "/home/arch/.environments/djanveg_dev/lib/python3.5/site-packages/django/core/management/base.py", line 356, in execute output = self.handle(*args, **options) File "/home/arch/.environments/djanveg_dev/lib/python3.5/site-packages/django/core/management/commands/test.py", line 72, in handle failures = test_runner.run_tests(test_labels) File "/home/arch/.environments/djanveg_dev/lib/python3.5/site-packages/django/test/runner.py", line 549, in run_tests old_config = self.setup_databases() File "/home/arch/.environments/djanveg_dev/lib/python3.5/site-packages/django/test/runner.py", line 499, in setup_databases self.parallel, **kwargs File "/home/arch/.environments/djanveg_dev/lib/python3.5/site-packages/django/test/runner.py", line … -
Django InlineModelAdmin formset set initial data
I've reading a lot of posts of this case, but i don't seem to be able to figure out a solution to this. I'm writing a Django app, I defined a ModelAdmin class with a inlines property, i also defined a InlineModelAdmin class that declare a formset property, something like this: class RichiestaChiamataFormSet(BaseInlineFormSet): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) class RichiestaChiamataInline(TabularInline): model = RichiestaChiamata fk_name = 'chiamata' formset = RichiestaChiamataFormSet class ChiamataAdmin(ModelAdmin): inlines = (RichiestaChiamataInline,) Now I would prepopulate the initial data of formset with params passed in request object, something like this: class RichiestaChiamataFormSet(BaseInlineFormSet): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) if self.request.GET.get('richiestachiamata_prodotti', False): prodotti = request.GET['richiestachiamata_prodotti'].split('|') self.initial = [{'prodotto': p} for p in prodotti] I readed a some posts like Django: Admin inline forms initial data for every instance but i could not pass the request variable to FormSet class Sorry for my english :) Thanks ! -
How to get the img src in django template?
I followed this post jQuery get the image src but it solved my problem partially. When i get the path of the initial src of img it give me: /static/app_name/src/blank.png which is true. But when i load another image using <input type="file"> and prompt the full path it give me this: data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAE+AbMDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDyrNPT3qOlWvMRkS544oB5+lID1oXJNWhDwM9aXHFHQUmcitEA1hxzUeOakJpueaYgC4p4XjrQpFPXpVoLjdg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9P8AMxbV/eOR+L/i7VPEeopcCWS3it23WsUTECHB4II/i962fD2u6P8AGrQo/DHjJ47LxhbIRp+qbQPPI/hPqT3Xv1GD -
Can we send a request object or keyword argument to modelformset_factory in django
I have the following view def application(request, uuid): application = get_object_or_404(LoanApplication, uuid=uuid) partners = FirmPartner.objects.filter(application=application) PartnerFormset = modelformset_factory(FirmPartner, form=FirmPartnerForm, can_delete=True, extra=1) if request.method == 'POST': ......... .......... But i want to make some fields in FirmPartnerForm required dynamically inside init method of form by using some values from request or keyword argument that we passed in like modelformset_factory(......application=application) ? So is it possible to send request object or any keyword argument to modelformset_factory ? as below modelformset_factory(FirmPartner, form=FirmPartnerForm, can_delete=True, extra=1, request=request, application=application) ? -
Django context processor constants work in dev but not in production
I have a context processor which makes constants available in templates, including base template. On my vagrant development server, using runserver, these work fine. I'm using Django 1.9.4 on both development and production. The production server uses WSGI. This is the context_processors.py from .constants import * def template_constants(request): return {'collection_name': COLLECTION_NAME, 'website_name': WEBSITE_NAME,} This is from settings.py TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.contrib.auth.context_processors.auth', 'django.template.context_processors.request', 'django.template.context_processors.debug', 'django.template.context_processors.i18n', 'django.template.context_processors.media', 'django.template.context_processors.static', 'django.template.context_processors.tz', 'django.contrib.messages.context_processors.messages', 'myapp.photos.context_processors.template_constants', ], }, }, ] I get no error messages, the variables simply don't have a value in the templates on production, so nothing is shown. Apart from deployment, the code on production and dev is exactly the same. -
How to create factory-boy factories for Django models with the same foreign key
I keep running into issues with my factories when two or more models have a common foreign key, and each one creates their own object when they should have the same. To illustrate the problem, here is a simplified model structure: class Language (models.Model): code = models.CharField(max_length=3, unique=True) class Audio(models.Model): language = models.ForeignKey(Language) soundfile = models.FileField() class Subtitles(models.Model): language = models.ForeignKey(Language) text = models.TextField() class Recording(models.Model): audio = models.ForeignKey(Audio) subtitles = models.ForeignKey(Subtitles) So a Recording has Audio and Subtitles, and both of those have a Language which is unique for each language code. Here are the factories for this structure. class LanguageFactory(factory.django.DjangoModelFactory): class Meta: model = Language class AudioFactory(factory.django.DjangoModelFactory): class Meta: model = Audio language = factory.SubFactory(LanguageFactory, code='en1') class SubtitlesFactory(factory.django.DjangoModelFactory): class Meta: model = Subtitles language = factory.SubFactory(LanguageFactory, code='en1') class RecordingFactory(factory.django.DjangoModelFactory): class Meta: model = Recording audio = factory.SubFactory(AudioFactory) subtitles = factory.SubFactory(SubtitlesFactory) It's a very common case that the audio and subtitles have the same language, since generally it's just a transcript. So I want a default RecordingFactory to have audio and subtitles with a language of 'en1' as code, as reflected in the factories above. But since each factory tries to create its own instance of language, instantiating a … -
Django passing from DropDownlist to View
I am trying to get the value of the Drop-down Menu Selected. I have done the following and it is returning a 'null' value. I think the problem is here: newupload = request.POST('nameProjects') but I'm not sure which on how to get it working. upload.html <form class="form" method="POST" action="upload"> <select id="ddProjects" name="nameProjects"> {% for project in projects %} <option value="{{ project.id }}">{{ project.name }}</option> {% endfor %} </select> </form> views.py def upload_new(request): newupload = Upload() projects = Project.objects.all() newupload = request.POST('nameProjects') newupload.save() return render(request, 'upload.html', {'projects':projects}) -
Django model for storing complex data arrays or list or tuples or dictionary?
I am new to programming and I am supposed to build a model to store data from a form where the user gives answers to lot of questions. What is the best way to store these kind of data ? I want to build a generic model to store set of questions and answers given by a particular user. Thinking of having the questions and answers in tuple set. visualisation is for example userA has tuple ((q1,a1),(q2,a2),(q3,a3),(q4,a4),) user B has ((q1,a1),(q2,a2),(q3,a3),(q4,a4),(q5,a5),(q6,a6),) or userA has dictionary{'q1':'a1','q2':'a2','q3':'a3','q4':'a4',} user B has {'q1':'a1','q2':'a2','q3':'a3','q4':'a4',','q5':'a5','q6':'a6',} what is the best way to store these type of scenario in the database and model construction in django. ? Any explanation or links to solve this problem is appreciated. thanks -
Django model inherided from abstract model returns TypeError when registered in admin
I get an error when I try to register inherited model: class Base(models.Model): class Meta: abstract=True class Derived(Base): pass admin.site.register(Derived) returns TypeError: 'type' object is not iterable at register line. The registry of not inherited models works fine. -
Django Rest Framework API by accept multiple input and output multiple data
I am two months with Django and API Rest Framework. I am developing an API to accept (userid and week_number), and output with (week_number and status). This is my model: class Timesheet(models.Model): userid = models.ForeignKey(User) week_number = models.CharField(max_length=2) status = models.CharField(max_length=255) This is my complete data example: [ { "id": 1, "userid": 1, "week_number": "32", "status": "completed" }, { "id": 2, "userid": 1, "week_number": "33", "status": "approved" }, { "id": 3, "userid": 1, "week_number": "34", "status": "incomplete" } ] API I want is like this: ACCEPT: userid=1 ACCEPT: week_number=33 ACCEPT: week_number=34 OUTPUT: week_number=33,status="approved" OUTPUT: week_number=34,status="incomplete" Note: I do not want data about week_number=32 I not sure how to code for this kind of API. Hope someone can help. -
How to remove an object from ManyToMany relationship in Django Rest Framework
I have a model with ManyToMany relationship. class File(models.Model): name = models.CharField(max_length=64) def __str__(self): return self.name class Folder(models.Model): name = models.CharField(max_length=64) files = models.ManyToManyField(File, related_name='folders', default=None) def __str__(self): return self.name Serializers: class FileSerializer(serializers.ModelSerializer): class Meta: model = models.File fields = '__all__' class FolderSerializer(serializers.ModelSerializer): files = FileSerializer(many=True, read_only=True) file = serializers.PrimaryKeyRelatedField(queryset=models.File.objects.all(), write_only=True, label='File Name') class Meta: model = models.Folder fields = ('id', 'name', 'files', 'file') I am able to add a file object to the folder. I am able to update the name of the folder too. But how do I remove a file object from the folder? -
Eroor in command django-admin manage.py make migrations
this is the entire output of this command then the output is looked like this.now as a beginner its very difficult for me to solve it -
Django page cache is caching header and footer
I'm using django page cache decorator to cache only my homepage, because of this, the header and footer are also getting cached. So, if a request comes from different URL, it is picking the header and footer from cache only. As my header and footer is dynamic for different urls. So, some links are giving 404. Is there any way to solve this problem either by purging header and footer only or something better? -
Why am I getting the error: OperationalError at /table/ no such table: table_book
Whenever I run the program, I get the following error: OperationalError at /table/ no such table: table_book It says that there's an error on line 7 in my template file. Here is my template.html: <table> <tr> <th>author</th> <th>title</th> <th>publication year</th> </tr> {% for b in obj %} <tr> <td>{{ b.author }}</td> <td>{{ b.title }}</td> <td>{{ b.publication_year }}</td> </tr> {% endfor %} </table> Here is my views.py: from django.shortcuts import render def display(request): return render(request, 'template.tmpl', {'obj': models.Book.objects.all()}) Here is my models.py: from django.db import models class Book(models.Model): author = models.CharField(max_length = 20) title = models.CharField(max_length = 40) publication_year = models.IntegerField() Here is my urls.py: from django.conf.urls import url from . import views urlpatterns = [ # /table/ url(r'^$', views.display, name='display'), ] Can somebody please tell me what is wrong? -
Text editor with django and angular
I'm working on a project where I need a text editor to edit article, I've also be able to put images in the article. Searching on internet about some text editor I found ckeditor. Now my doubt is, ok, there's check editor for django and for angular, I suppose I've to use angular one, and then pass with drf to django? Which field do I have to use in django to store the content? I have then, through DRF, send everything to mobile app, how is the proper way to manage the image inside the app? It has to go offline, so I've to download everything on the mobile.