Hello, thanks a lot for your answers.
I am very embarrassed to say that I went a bit too fast in my testing of
nested ArrayField, and it turns out that it actually fits my use case.
   def test_nested_array_accepts_1D_array(self):
    instance = NestedIntegerArrayModel(id=1, field=[1, 2, 3])
    instance.save()
    instance_from_db = NestedIntegerArrayModel.objects.get(id=1)
    self.assertEqual(instance_from_db.field, [1, 2, 3])


This test actually passes, sorry for the noise :S.

Best regards,
Liamine

Le jeu. 11 août 2022 à 08:12, Adrian Torres <atorr...@redhat.com> a écrit :

> Hi Liamine,
>
> I think there's various solutions you could try before going the custom
> field route:
>
> * You could try just using the 2D version and use some sentinel value for
> the date (NULL?) to treat the case where you just want an array of N prices.
> * You could try using django-polymorphic [1] which would allow you to
> define one "StandardPricingProduct" model and one "CalendarPricingProduct"
> model, and be able to query them together (e.g. get all products regardless
> of "type").
> * You could try Jacob's suggestion.
> * You could try creating a pricing model and have a FK between Pricing and
> Product -- I know you want to avoid this, but to me it sounds simpler and
> more maintainable than going the custom field route.
>
> Cheers,
> Adrian
>
> [1] https://django-polymorphic.readthedocs.io/en/stable/
>
> On Wednesday, August 10, 2022 at 6:44:55 PM UTC+2 jacob...@gmail.com
> wrote:
>
>> Hello Liamine,
>> Django offers a JSONField
>> <https://docs.djangoproject.com/en/4.1/ref/models/fields/#jsonfield>
>> which can be used to store an array.
>> You can use it to store a list of prices. What's the benefit of using an
>> array instead of JSON?
>> – Jacob
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/bbbfb68d-1167-45aa-bf8d-4f8b0346c411n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/bbbfb68d-1167-45aa-bf8d-4f8b0346c411n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 

Cordialement,

[image: img] <https://signitic.app/linkc/L3BtUHlaZUE-L3A4PQ>


*Liamine Cheridi*Backend Engineer
0630178896

[image: img] <https://signitic.app/linkc/L3BtUHlaZUE-L1pzPQ> [image: img]
<https://signitic.app/linkc/L3BtUHlaZUE-L3A4PQ> [image: img]
<https://signitic.app/linkc/L3BtUHlaZUE-L1prPQ> [image: img]
<https://signitic.app/linkc/L3BtUHlaZUE-L1pnPQ>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CABexJma6bSVDe9Xhg_pe3f9URgBYQNaobr6cdsr1Fa7t0ZVe-w%40mail.gmail.com.

Reply via email to