Skip to content
Advertisement

Tag: django

how do I efficiently test this Django model?

I’m building an authentication system for a website, I don’t have prior test experience with Django. I have written some basic tests. the model, and model manager, and my tests, fortunately all the passes, and my question is, are these tests overdone or underdone or normal? What should be tested in a model? is there any procedure missing? anything wrong

Django rest framework override page_size in ViewSet

I am having problem with django rest framework pagination. I have set pagination in settings like – Below is my viewset. I want to set different page size for this viewset. I have tried setting page_size and Paginate_by class variables but list is paginated according to PAGE_SIZE defined in settings. Any idea where I am wrong ? Answer I fixed

Django migrate ProgrammingError: syntax error at or near “”

I’m learning django (1.9.2) on a practice web site and a postgresql database with psycopg2. I defined a model with a certain attribute “preview” and later deleted the attribute entirely. Despite having removed it, django seems to be referencing that old definition perhaps from a cache or something. The makemigrations command seems to work fine, reflecting every change that I

Jinja loop.index does not print

When running the following jinja code, I only get “Column info” printed. Why the index does not appears ? Answer It sounds like the template is being treated as a Django template, not a Jinja template. Using {{ loop.index }} should work in a Jinja template, but wouldn’t work in a Django template, where you would use {{ forloop.counter }}

How does a Django UUIDField generate a UUID in Postgresql?

After reading this blog post https://blog.starkandwayne.com/2015/05/23/uuid-primary-keys-in-postgresql/ I wanted to know more about how Django generates uuid because I am using them as my pk. Well, according to the docs, https://docs.djangoproject.com/es/1.9/ref/models/fields/#uuidfield, Django is relying on the Python UUID module https://docs.python.org/3/library/uuid.html#uuid.UUID. But there are many kinds of UUID, and it is not at all clear to me which one is being generated

I want my django rest framework serializer to accept input but not add to model

I removed some fields from my model, but I want the serializer to still accept the fields as input. How do I have fields the serializer accepts but doesn’t use? Answer From http://www.django-rest-framework.org/api-guide/serializers/ You can add extra fields to a ModelSerializer or override the default fields by declaring fields on the class, just as you would for a Serializer class.

“no such table” exception

In Django I added models into models.py. After manage.py makemigrations, manage.py migrate raised this exception: django.db.utils.OperationalError: no such table: auth_test_usertranslatorprofile I removed all old migrations and run makemigrations and migrate again which seemed to work. It didn’t help because when I click User customer profiles of User translator profiles it raises exception: models.py: admin.py: What is the problem? Answer I

Django attaching events to days in a calendar?

I have built a basic calendar which generates a table with the current month (taken from the URL) using the built-in calendar.Calendar function, but I would like to attach events to the days that are generated. What would be the best way to do that? Currently in my views: And in my template I can call the weeks and days

Advertisement