Skip to content
Advertisement

Tag: django-models

Idempotent record creation: is it better to use a unique constraint or check for existence before inserting a record?

I’ve recently been wondering what’s generally the best approach for ensuring that the creation of database records is idempotent. The two approaches I can think of are: Checking whether a record already exists before executing an INSERT Using a unique constraint on the relevant columns to insure two records with the same values cannot exist This seems like an example

Django ORM Left Join onto same table

I have a custom permissions system in a django project that can link any user to any specific model instance to grant permission on that object. It is more complex than this, but boiled down: I want to query for all permissions for any user, that are linked to the same content_object(s) that a particular user has been granted permission(s)

Django: How to mangle through relations

I have an instance of ModelA and want to query all instances of ModelC which are related to ModelA through ModelB. ModelA -> all ModelB instances with FK rel_a = ModelA -> rel_c.all() I know how I would do this in SQL but I really do not get how I should unmangle these relations Answer You can query with a

Advertisement