mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 13:17:50 +02:00
Add a CSV export functionality in admin and add price fields (#41)
* Implement an action do download data in csv * Refactor CSV download * Move price to main models and add csv to bookshelf * Update template and API * Small refactoring
This commit is contained in:
36
ram/bookshelf/migrations/0019_basebook_price.py
Normal file
36
ram/bookshelf/migrations/0019_basebook_price.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# Generated by Django 5.1.4 on 2024-12-29 17:06
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def price_to_property(apps, schema_editor):
|
||||
basebook = apps.get_model("bookshelf", "BaseBook")
|
||||
for row in basebook.objects.all():
|
||||
prop = row.property.filter(property__name__icontains="price")
|
||||
for p in prop:
|
||||
try:
|
||||
row.price = float(p.value)
|
||||
except ValueError:
|
||||
pass
|
||||
row.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookshelf", "0018_alter_basebookdocument_options"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="basebook",
|
||||
name="price",
|
||||
field=models.DecimalField(
|
||||
blank=True, decimal_places=2, max_digits=10, null=True
|
||||
),
|
||||
),
|
||||
migrations.RunPython(
|
||||
price_to_property,
|
||||
reverse_code=migrations.RunPython.noop
|
||||
),
|
||||
]
|
Reference in New Issue
Block a user