Skip to content
Advertisement

Tag: postgresql

How to generate indexes for related fields on Django models?

Say we’re building a Django-based site that clones Medium.com’s URL structure, where you have users and articles. We’d probably have this model: We want to be able to build URLs that look like /<username>/<slug>/. Since we’re going to have billions of articles and zillions of pageviews, we want to put an index on that model: But this causes the makemigrations

Prevent DateRangeField overlap in Django model?

Now that Django supports the DateRangeField, is there a ‘Pythonic’ way to prevent records from having overlapping date ranges? Hypothetical use case One hypothetical use case would be a booking system, where you don’t want people to book the same resource at the same time. Hypothetical example code Answer I know that the answer is old, but now you can

How can I serialize a queryset from an unrelated model as a nested serializer?

I’m trying to add a nested serializer to an existing serializer based on some criteria of the parent model, not a foreign key. The use case is to return a ‘Research’ object with an array of ‘ResearchTemplate’ objects that are identified by filtering on a Postgres ArrayField. Models class Research(TimeStampedModel): category = models.CharField(max_length=100, choices=RESEARCH_TEMPLATE_CATEGORIES, default=’quote’) body = models.CharField(max_length=1000, blank=True, default=”)

Connection refused with postgresql using psycopg2

psycopg2.OperationalError: could not connect to server: Connection refused Is the server running on host “45.32.1XX.2XX” and accepting TCP/IP connections on port 5432? Here,I’ve open my sockets. I googled that I should modify this pg_hba.conf,but in my postgresqlroot files, I didn’t find this file at all. Also I’ve succeed in connecting my another server. Thanks. Here,I’ve modified the pg_hba.conf,updated thishost all

Django: Query Group By Month

How to calculate total by month without using extra? I’m currently using: django 1.8 postgre 9.3.13 Python 2.7 Example. What I have tried so far. and also this one, the answer seems great but I can’t import the TruncMonth module. Django: Group by date (day, month, year) P.S. I know that this question is already asked multiple times but I

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

Advertisement