fix customer view and edit
This commit is contained in:
1 parent
81335b1439
commit
d5c22a39dc
13 files changed
+329
-81
No files matched your search
@@ -0,0 +1,25 @@
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def backfill_customer_profiles(apps, schema_editor):
|
||||
User = apps.get_model("accounts", "User")
|
||||
CustomerProfile = apps.get_model("customers", "CustomerProfile")
|
||||
database = schema_editor.connection.alias
|
||||
missing_users = (
|
||||
User.objects.using(database)
|
||||
.filter(account_type="CUSTOMER", customer_profile__isnull=True)
|
||||
.values("pk", "first_name", "last_name")
|
||||
)
|
||||
batch = []
|
||||
for user in missing_users.iterator(chunk_size=500):
|
||||
batch.append(CustomerProfile(user_id=user["pk"], first_name=user["first_name"][:100], last_name=user["last_name"][:100]))
|
||||
if len(batch) == 500:
|
||||
CustomerProfile.objects.using(database).bulk_create(batch, ignore_conflicts=True, batch_size=500)
|
||||
batch.clear()
|
||||
if batch:
|
||||
CustomerProfile.objects.using(database).bulk_create(batch, ignore_conflicts=True, batch_size=500)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [("customers", "0005_contacteditlog")]
|
||||
operations = [migrations.RunPython(backfill_customer_profiles, migrations.RunPython.noop)]
|
||||
Reference in new issue
Block a user