Reputation: 13880
I have two databases:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'new',
'USER': 'xxxxx',
'PASSWORD': 'xxxxx',
'HOST': '',
'PORT': '',
},
'old': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'old',
'USER': 'xxxxx',
'PASSWORD': 'xxxxx',
'HOST': '',
'PORT': '',
},
}
and model:
class MyModel(models.Model):
user = models.ForeignKey(User)
title = models.CharField(max_length=200)
text = models.TextField()
data = some other data
Old database contains some removed entries and some of the new database.How to filter entries from new database that there are no entries from the old database?
Upvotes: 0
Views: 54
Reputation: 13880
I made this:
f1 = MyModel.objects.using('old').all()
pids = [p.id for p in f1]
f2 = MyModel.objects.exclude(id__in=pids).filter()
But I don't know if it is good.
Upvotes: 1