Help: Data model in django

11 views
Skip to first unread message

Ricken Cheng

unread,
Mar 9, 2017, 1:19:38 PM3/9/17
to Django users
Hi:
   I am a beginner using django, I want to build a flexible data model like this:
   
Item_ID         Attribute    Value
1                      Attr1         V1
1                      Attr2         V2
2                      Attr1         V3
2                      Attr2         V4
1                      Attr3         V5

Uses can add new attribute (attr 4, 5..) without changing the database (do not add new columns)
How can I realize it in model, view and form with the function of creating Item and searching items on selected attrs?
The main problem confused me is that I cannot link form with model since the attribute is actually values not truly attributes.


Thanks!

Shawn Milochik

unread,
Mar 9, 2017, 1:23:58 PM3/9/17
to django...@googlegroups.com
Are you using PostgreSQL? Maybe you can use JSONField.

Melvyn Sopacua

unread,
Mar 9, 2017, 3:31:02 PM3/9/17
to django...@googlegroups.com

On Thursday 09 March 2017 09:49:03 Ricken Cheng wrote:

> Hi:

> I am a beginner using django, I want to build a flexible data model

> like this:

>

> Item_ID Attribute Value

> 1 Attr1 V1

> 1 Attr2 V2

> 2 Attr1 V3

> 2 Attr2 V4

> 1 Attr3 V5

>

 

That's nice, but what are you supposed to do with it? If it means nothing to the application, then why make attributes and not just add a text field with "attributes"?

And yes, if you want some kind of structure for rendering, then JSONField is a good choice.

--

Melvyn Sopacua

Reply all
Reply to author
Forward
0 new messages