On Thu, Mar 10, 2016 at 8:17 AM, Markus Holtermann
<[email protected]> wrote:
> Hi Akshesh,
>
> thank you for your proposal! Sounds like a good plan.
>
> On Thursday, March 10, 2016 at 8:16:10 AM UTC+11, akki wrote:
>
>>> Once the index is added to a model, the model can inject itself into the
>>> index, or the schema editor can use the originating model to get data it
>>> needs. No need to pass the model into the index type I think. Regarding the
>>> name, I'm unsure if I prefer a name=Index() or an Index(name='') approach.
>>> It'd be good to see that choice in your proposal with a couple of pros and
>>> cons.
>>
>>
>> Well, since we are defining these indexes in a list (to be stored in
>> Meta.indexes) I would go with the Index(name='') approach.
>
>
> I'd prefer the Index(name='') approach
>
> class MyModel(models.Model):
> field1 = models.CharField()
> field2 = models.CharField()
>
> class Meta:
> indexes = [
> Index('field1', 'field2', name='some_index_across_two_columns'),
> 'field2', # Would be the same as Index('field2'), an index on
> this one column -- name derived from field name: field2_index
> Index(ToLower('field1')), # A functional index on field1 --
> name derived from field name and functions: field1_tolower_index
> ]
>
> That way you should also be able to check for duplicate index names.
How about
class MyModel(models.Model):
field1 = models.CharField()
field2 = models.CharField()
field1_idx = models.Index('field1')
field2_lower_idx = models.Index(ToLower('field2'))
The main advantage is that the same syntax can be used for custom
indexes, constraints, composite fields and so on. Internally we could
of course have the same representation for indexes as before.
- Anssi
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/CALMtK1Eet%3DzPTKXJJpuRy8b0tWF%2BaA9-QaT%2BzfF%3DGV6wAd3N3g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.