End-user defined fields, how would you approach it?

113 views
Skip to first unread message

Bernardo Pires

unread,
Jan 29, 2012, 3:18:41 AM1/29/12
to Django developers
Good Morning guys!
Scenario is the following. For some models on Django, I would like to
allow the end user to define his own fields. It would be great if I
could keep all Django awesome features like the ORM, so I can still do
calls like field__gte to search on the model, still have field
validation according to field type, etc. I've thought about two ways
of doing this, and I'm more than open for new suggestions. Any
feedback would be VERY appreciated.

1. The first approach, is the Entity-Attribute-Value (
http://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_model
), which django already has an app for. See http://code.google.com/p/django-custom-field/
I think this would be an OK solution, but I lose the ability to do
"mymodel.objects.filter(custom_field_x=something)". Maybe there's a
way to regain the ORM, any ideas? But I've heard so many bad stories
about this method that I'm little scared to use it.

2. The second approach would be to have a database table for each of
the users (probably no more than a 1000). I've read django has
something in the lines of inspectdb, which actually checks which
fields are there and produces the model for you. This could be useful
but I think maybe I should store the fields this particular user has
created and somehow dinamically tell django, hey, we also have this
fields in this model. Is this possible? I know it's generally bad to
have different tables for each user, but considering this scenario,
how would you guys rate this method, would it be ok to have one table
for each user?

The model that requires custom fields is for example Person. They
might want a custom field to store address, blood type, or any other
thing.

MANY THANKS in advance! Have a nice sunday!
Bernardo Pires

Etienne Robillard

unread,
Jan 29, 2012, 10:53:20 AM1/29/12
to django-d...@googlegroups.com, Bernardo Pires
Hi,

> 2. The second approach would be to have a database table for each of
> the users (probably no more than a 1000). I've read django has
> something in the lines of inspectdb, which actually checks which
> fields are there and produces the model for you. This could be useful
> but I think maybe I should store the fields this particular user has
> created and somehow dinamically tell django, hey, we also have this
> fields in this model. Is this possible? I know it's generally bad to
> have different tables for each user, but considering this scenario,
> how would you guys rate this method, would it be ok to have one table
> for each user?

Its not really the functional aspect that burdens me but rather to
understand why on Earth a web site would need to store individual data
on a per-user basis, unless for fascists tracking/monitoring reasons of
your visitors.. As for this reason alone I'd decline this for political
reasons. (-1)

> The model that requires custom fields is for example Person. They
> might want a custom field to store address, blood type, or any other
> thing.

Whatever. ;-)

> MANY THANKS in advance! Have a nice sunday!
> Bernardo Pires
>

cheers,
Etienne

Ivan Kharlamov

unread,
Jan 29, 2012, 10:58:56 AM1/29/12
to django-d...@googlegroups.com

Bernardo, Hello.

For other options checkout this guide:
http://stackoverflow.com/a/7934577/497056

Best regards,
Ivan Kharlamov

Bernardo Pires

unread,
Jan 29, 2012, 11:42:09 AM1/29/12
to Django developers
That's a great reference, many thanks ivan!

On Jan 29, 4:58 pm, Ivan Kharlamov <the.paper....@gmail.com> wrote:
> On 01/29/2012 12:18 PM, Bernardo Pires wrote:
>
>
>
>
>
>
>
>
>
> > Good Morning guys!
> > Scenario is the following. For some models on Django, I would like to
> > allow the end user to define his own fields. It would be great if I
> > could keep all Django awesome features like the ORM, so I can still do
> > calls like field__gte to search on the model, still have field
> > validation according to field type, etc. I've thought about two ways
> > of doing this, and I'm more than open for new suggestions. Any
> > feedback would be VERY appreciated.
>
> > 1. The first approach, is the Entity-Attribute-Value (
> >http://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_m...
> > ), which django already has an app for. Seehttp://code.google.com/p/django-custom-field/

Etienne Robillard

unread,
Jan 29, 2012, 12:16:59 PM1/29/12
to django-d...@googlegroups.com

>> For other options checkout this guide:http://stackoverflow.com/a/7934577/497056
>>
>> Best regards,
>> Ivan Kharlamov

Probably a really mediocre reference assuming its on stackoverflow.com
already... :-)

Cheers
E


Simon Charette

unread,
Jan 29, 2012, 12:21:15 PM1/29/12
to django-d...@googlegroups.com
I've been working on a similar project which takes the django-dynamo project a bit further.

It's undocumented ATM but you can find the code at: https://github.com/charettes/django-mutant

Ivan Kharlamov

unread,
Jan 29, 2012, 12:31:07 PM1/29/12
to django-d...@googlegroups.com

Well, I'm not going to pretend that I'm a superstar programmer. I wrote
this reference because some time ago I've had a need to implement
dynamic Django models and didn't find any up to date cheat sheet or side
by side comparison of different dynamic model implementations.

Maybe you know better. Why don't you share your knowledge?

> Cheers
> E
>
>

Etienne Robillard

unread,
Jan 29, 2012, 12:39:49 PM1/29/12
to django-d...@googlegroups.com

Please reread my initial reply to this thread for explanation as i'm
feeling bored of repeating sometimes... :-)

cheers,

E

Ivan Kharlamov

unread,
Jan 29, 2012, 12:55:36 PM1/29/12
to django-d...@googlegroups.com
> Its not really the functional aspect that burdens me but rather to understand why on Earth a web site would need to store individual data on a per-user basis, unless for fascists tracking/monitoring reasons of your visitors.. As for this reason alone I'd decline this for political reasons. (-1)

Oh, I've got your point! Yes, it is true that dynamic models are only
for communist hippie weirdos such as medical workers etc. ^-^

> cheers,
>
> E
>

Aymeric Augustin

unread,
Jan 29, 2012, 1:40:04 PM1/29/12
to django-d...@googlegroups.com
Hello Etienne,

The three messages you posted in this thread aren't appropriate on this mailing list, both in terms of contents and tone.

Please stay on topic, respect other members of the community, and if you don't have anything constructive to say, refrain from posting — even with a smiley.

Thanks,

--
Aymeric Augustin.

Etienne Robillard

unread,
Jan 29, 2012, 1:52:18 PM1/29/12
to django-d...@googlegroups.com
On 01/29/2012 01:40 PM, Aymeric Augustin wrote:
> Hello Etienne,
>
> The three messages you posted in this thread aren't appropriate on this mailing list, both in terms of contents and tone.
>
> Please stay on topic, respect other members of the community, and if you don't have anything constructive to say, refrain from posting � even with a smiley.
>
> Thanks,
>

They were just fine. Please stop trolling and respect the little freedom
of expression we still have.

E

Dustin Farris

unread,
Jan 29, 2012, 1:26:50 PM1/29/12
to Django developers
Without getting so complicated, something basic like key-value
models.. e.g.

class Person(models.Model):
pass

class Key(models.Model):
name = models.CharField()

class Attribute(models.Model):
person = models.ForeignKey(Person)
key = models.ForeignKey(Key)
value = models.CharField()


Which would then allow your desired filters:

people_with_brown_hair = Person.objects.filter(
attribute=Attribute.objects.get(key=Key.objects.get(name='hair
color'), value='brown')
)

Etienne Robillard

unread,
Jan 29, 2012, 3:44:32 PM1/29/12
to John Hensley, Django developers, django...@googlegroups.com
On 01/29/2012 02:46 PM, John Hensley wrote:
> Etienne,
>
> I sympathize with you regarding the ever-decreasing civil liberties, I really do, but the django-developers list is not the place for this. If a core developer tells you that your messages aren't appropriate, the only correct response is, "Sorry, won't happen again." You've been asked repeatedly now to take the politics somewhere else. Please have the maturity and civility to do so.
>
> John
>
You're missing the point totally.

The point is that as most as everyone on this list, we have the right to
discuss things which feels on topic with this list without being
discriminated for no reasons.

Now that has nothing to do with mediocre questions. Don't expect
anything from me but harsh responses when you're expecting only mediocre
answers, as this is really not more on-topic than
was SOPA.

E

Etienne Robillard

unread,
Jan 29, 2012, 3:55:49 PM1/29/12
to django-d...@googlegroups.com

LOL- Not all medical workers should be communist hippie weirdos... :-)

cheers,
E

Etienne Robillard

unread,
Jan 29, 2012, 4:18:58 PM1/29/12
to django-d...@googlegroups.com, Ivan Kharlamov

sorry for the interruptions, what are we saying now? :-)

Please continue discussing this, if you feel its appropriate to let have
for each users a SQL table..

cheers,
E


Łukasz Rekucki

unread,
Jan 29, 2012, 4:27:31 PM1/29/12
to django-d...@googlegroups.com
First of all, this whole topic doesn't belong on django-developers in
the first place as it's strictly a user question (I didn't see any
proposal to change anything in the core, etc.). In the future, please
post to django-users with question about using Django.

On 29 January 2012 21:44, Etienne Robillard <anime...@gmail.com> wrote:
> On 01/29/2012 02:46 PM, John Hensley wrote:
>>
>> On Jan 29, 2012, at 1:52 PM, Etienne Robillard wrote:
>>
>>> On 01/29/2012 01:40 PM, Aymeric Augustin wrote:
>>>>
>>>> Hello Etienne,
>>>>
>>>> The three messages you posted in this thread aren't appropriate on this
>>>> mailing list, both in terms of contents and tone.
>>>>
>>>> Please stay on topic, respect other members of the community, and if you

>>>> don't have anything constructive to say, refrain from posting — even with a


>>>> smiley.
>>>>
>>>> Thanks,
>>>>
>>>
>>> They were just fine. Please stop trolling and respect the little freedom
>>> of expression we still have.
>>
>>
>> Etienne,
>>
>> I sympathize with you regarding the ever-decreasing civil liberties, I
>> really do, but the django-developers list is not the place for this. If a
>> core developer tells you that your messages aren't appropriate, the only
>> correct response is, "Sorry, won't happen again." You've been asked
>> repeatedly now to take the politics somewhere else. Please have the maturity
>> and civility to do so.
>>
>> John
>>
> You're missing the point totally.
>
> The point is that as most as everyone on this list, we have the right to
> discuss things which feels on topic with this list without being
> discriminated for no reasons.
>

You're not discriminated - everyone is treated the same way here and
judged only by their actions. By disobeying the rules of this list,
you're disrespecting it's members. If you disagree with the rules of
this community, you don't have to be part of it. Insulting it's core
members surely doesn't help you convince us, that it's a good choice
to accept your definition of "things which feels on topic with this
list".

--
Łukasz Rekucki

Etienne Robillard

unread,
Jan 29, 2012, 5:05:23 PM1/29/12
to django-d...@googlegroups.com

OK good. I see your points but please observe I'm still searching where
I'm "disobeying" the rules ?

Anyways, thanks trying not to disturb the thread. But i disagree it
should be on django-users as now that I'm thinking more of this
possiblity to have one table per user.


Russell Keith-Magee

unread,
Jan 29, 2012, 7:51:48 PM1/29/12
to django-d...@googlegroups.com

Let me help.

Firstly:

"...unless for fascists tracking/monitoring reasons of your visitors.."

You just called the OP a fascist, based purely on an architectural decision.

Secondly:

"Probably a really mediocre reference assuming its on stackoverflow.com already... :-)"

You just called the entire population of Stack Overflow mediocre, and implied that Ivan specifically was mediocre because he recommended it.

Thirdly:

"Don't expect anything from me but harsh responses when you're expecting only mediocre answers"

We don't expect harsh responses *at all*. If you can't say something constructive, say nothing at all.

None of these three comments were necessary, or were consistent with the tone that we expect of participants in Django-developers. If you don't like what someone is doing with technology, refrain from commenting. If you don't like Stack Overflow, don't recommend it; if someone recommends something from Stack Overflow that you disagree with, point out the specific flaws in the specific suggestion that has been made. If you think someone is asking bad questions, ignore them; or if you're feeling particularly helpful, assist them by providing constructive guidance on asking better questions.

Regarding your reference to discussions about SOPA -- you'll notice that when SOPA came up recently, it was very rapidly pointed out that such discussions were off-topic for Django-developers, unless there was a specific call to action for the Django codebase.

This isn't censorship, or the jackboot of the thought police. It's the Django core team ensuring that we maintain a civil community.

Yours,
Russ Magee %-)

Etienne Robillard

unread,
Jan 29, 2012, 8:51:15 PM1/29/12
to django-d...@googlegroups.com

i still think stackoverflow.com is retarded. Ie it attracts stupid
peoples with stupid questions towards stupid solutions. :-)

As for your opinions, I respect them as always and that should be all
the same for me, ie without stupid moderation/trolling.

Otherwise this is only fascist moderation and I'm making only very
polite comments when talking about SOPA. So please be cool and observe
that the net is still a free place to discuss without stupid trolls to
dictate content.

Cheers,
E

Russell Keith-Magee

unread,
Jan 29, 2012, 9:28:46 PM1/29/12
to django-d...@googlegroups.com

On 30/01/2012, at 9:51 AM, Etienne Robillard wrote:

> i still think stackoverflow.com is retarded. Ie it attracts stupid peoples with stupid questions towards stupid solutions. :-)
>
> As for your opinions, I respect them as always and that should be all the same for me, ie without stupid moderation/trolling.
>
> Otherwise this is only fascist moderation and I'm making only very polite comments when talking about SOPA. So please be cool and observe that the net is still a free place to discuss without stupid trolls to
> dictate content.


http://www.youtube.com/watch?v=G2y8Sx4B2Sk

Let me be perfectly clear.

There is a world of difference between "I don't think that XYZ, as suggested by StackOverflow, is a very good idea", and "StackOverflow is for stupid people with stupid questions". Unprovoked accusations of fascism, or suggesting that an individual is mediocre is not a "very polite comment".

You are free to hold any opinion you want. You are free to provide any constructive advice that you care to share.

You're not free to use the Django community as a platform to call people stupid, mediocre, or fascists.

I am not saying you can't express your opinions. I'm telling you that when you express your opinions in an official Django forum, you'll keep a civil tongue in your mouth. That isn't censorship -- it's called being polite.

If you can't maintain a civil tone, then I would kindly ask you to refrain from posting. If you continue to maintain an uncivil tone, then for the good of the Django community, I'll ban you from posting.

Yours,
Russ Magee %-)

Etienne Robillard

unread,
Jan 30, 2012, 6:09:12 AM1/30/12
to django-d...@googlegroups.com

So why are you now insisting on putting it on the personal side unless
for this particular reasons of banning me ? You're perfectely fitting
into a idiot for me and no matter what I could be attempting to
say/reply it would still be an idiot response.

So please go ahead and ban me from this group and enjoy
mediocre/prefabricated content as i'm getting tired of discrimination
and retarded peoples like you in particular.

Cheers,
E

Etienne Robillard

unread,
Jan 30, 2012, 6:22:13 AM1/30/12
to John Hensley, Django developers, django...@googlegroups.com
On 01/29/2012 02:46 PM, John Hensley wrote:
> On Jan 29, 2012, at 1:52 PM, Etienne Robillard wrote:
>
> Etienne,
>
> I sympathize with you regarding the ever-decreasing civil liberties, I really do, but the django-developers list is not the place for this. If a core developer tells you that your messages aren't appropriate, the only correct response is, "Sorry, won't happen again." You've been asked repeatedly now to take the politics somewhere else. Please have the maturity and civility to do so.
>
> John
>

John, even with your reply your putting politics on the topic. It just
deplorable we let people destroy threads on the basis on content
filtering just because they have the 'moderation' flag set and they can
impose whatever (mediocre) rules they wish.. :-)

Bernardo Pires

unread,
Jan 30, 2012, 8:20:39 AM1/30/12
to Django developers
Someone has PMS.

On Jan 30, 12:22 pm, Etienne Robillard <animelo...@gmail.com> wrote:
> On 01/29/2012 02:46 PM, John Hensley wrote:
>
>
>
>
>
>
>
>
>
> > On Jan 29, 2012, at 1:52 PM, Etienne Robillard wrote:
>
> >> On 01/29/2012 01:40 PM, Aymeric Augustin wrote:
> >>> Hello Etienne,
>
> >>> The three messages you posted in this thread aren't appropriate on this mailing list, both in terms of contents and tone.
>
> >>> Please stay on topic, respect other members of the community, and if you don't have anything constructive to say, refrain from posting even with a smiley.

Etienne Robillard

unread,
Jan 30, 2012, 8:57:00 AM1/30/12
to django-d...@googlegroups.com
On 01/30/2012 08:20 AM, Bernardo Pires wrote:
> Someone has PMS.

you mean like Post-menstrual syndrome ? Are you kidding.. 8-)

i'm just concerned by whatever I could touch would be immediately
backfired as OT..

E

John Hensley

unread,
Jan 30, 2012, 9:01:28 AM1/30/12
to django-d...@googlegroups.com, django...@googlegroups.com
On Jan 30, 2012, at 6:22 AM, Etienne Robillard wrote:

> John, even with your reply your putting politics on the topic.

Yes, apparently I did prolong this, even by replying off list. I won't again. Apologies, everyone.


Will Hardy

unread,
Jan 30, 2012, 9:35:01 AM1/30/12
to django-d...@googlegroups.com
In the interests of the thousands of developers on this list and their
valuable time, I have to agree that this thread is very off topic.
I'll focus on the original question, below is a quick justification
for anyone who is interested.

I can't see a reason to build anything into Django core to support
dynamic models, as it can be done reasonably well in a third party
app. The amount of extra tests that would be written to ensure that it
works as advertised would be nontrivial, and only worth considering if
there were a third party app with an appropriate level of abstraction
(ie flexibility).

There are some areas that require hacks, for example getting Django's
Admin to update its cached models/admin definitions when needed. But
in the end, core support of a feature like this would distract the
core developers from more important tasks. If there is anything that
doesn't work with Django, it would be more productive to open a ticket
to make that component more flexible.

I would also like to dissuade anyone from taking this road unless they
are *certain* that they need it, that all the other approaches are
insufficient. It makes a number of things much more complicated, makes
your test suite slower and slows down development of a number of
things that Django normally gives you for free.

Cheers,

Will

Jacob Kaplan-Moss

unread,
Jan 30, 2012, 10:54:52 AM1/30/12
to django-d...@googlegroups.com
Bernardo Pires wrote:
> Someone has PMS.

This is well beyond the line. Insults and sexism aren't acceptable here.
At all.

You need to change your behavior immediatly or I'm going to ban you. I
expect the next message I see from you to be within the realm of
acceptable, professional discourse.

If you have any questions, email me off-list.

Jacob

Jacob Kaplan-Moss

unread,
Jan 30, 2012, 11:09:40 AM1/30/12
to django-d...@googlegroups.com
Reading further, I see you were replying to someone else being inappropriate. Well fair enough, and I can forgive you for getting angry -- this whole thread is a mess. So, Bernardo, sorry I went straight to the threats of banning; I see now I was confused. Still, responding in kind isn't the way to go: just leave the thread.

This goes for everyone paying attention: I expect a certain level of decorum here. I don't want to have to enforce it -- we're all professionals, and we should be able to act as such. Let's set and maintain a higher standard here.

Jacob

Reply all
Reply to author
Forward
0 new messages