How to create dynamic models in django??

1.880 visualizações
Pular para a primeira mensagem não lida

Prashanth Patelc

não lida,
26 de fev. de 2022, 22:42:5526/02/2022
para django...@googlegroups.com
How to create dynamic models in django rest framework?
Is there any chance to create dynamic models with APIs

Any examples please send me thanks in advance..

1) Requirement is need create table name and fields in frontend
2) we are  getting the data and store in to the db create db structure
3) get the table name and fields create table in backend &postgresql store to
4)this code don't update or add into the models 
5)store the data into the tables 
4)get the data into the tables using orm or any raw queries

Antonis Christofides

não lida,
27 de fev. de 2022, 02:00:5627/02/2022
para django...@googlegroups.com

Short answer: I don't know. It probably isn't straightforward, but it's doable in principle.

Longer answer: Django hasn't been designed with this case in mind. It's possible it's not the appropriate tool for the job (but again it might be, I don't know). In my experience you should avoid doing such things—it's likely to lead to an unmanageable code mess. Keep it simple. Consider working without a relational database.

Regards,

Antonis

Antonis Christofides
+30-6979924665 (mobile)
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMCU6Coop%3DVU67%2B1Ui%2BswvA2xijUYcre%2B%3D-Z_CzLnf-1pRRXUw%40mail.gmail.com.

Heman Okumbo

não lida,
27 de fev. de 2022, 11:42:2627/02/2022
para django...@googlegroups.com

Steve Smith

não lida,
27 de fev. de 2022, 12:56:5827/02/2022
para django...@googlegroups.com
My two cents.  I've been trying to do a very similar thing...I've accomplished it in Django....using Formsets....It was painful....the documentation on Formsets is scarce in my opinion and to get them to work is a lot of trial and error, not to mention complexity with corresponding Javascript.  At least for me it was.  I'm not using the rest framework as it relates to a table and rows but I am using them with a server based Django installation....so I'm not sure how this applies to your use case.  I have recently started experimenting with HTMX....to ultimately replace formsets and I'm pretty close to having it figured out.  Again with HTMX, there's not a lot of documentation so it's been a ton of trial and error....If any of this resonates with you...let me know and I can provide some more specifics.

Steve


From: django...@googlegroups.com <django...@googlegroups.com> on behalf of Antonis Christofides <ant...@antonischristofides.com>
Sent: Sunday, February 27, 2022 12:58 AM
To: django...@googlegroups.com <django...@googlegroups.com>
Subject: Re: How to create dynamic models in django??
 

Shaheed Haque

não lida,
27 de fev. de 2022, 16:32:4727/02/2022
para django...@googlegroups.com

Clive Bruton

não lida,
28 de fev. de 2022, 06:57:2828/02/2022
para django...@googlegroups.com

On 27 Feb 2022, at 17:54, Steve Smith wrote:

> ...the documentation on Formsets is scarce in my opinion and to get
> them to work is a lot of trial and error...

To massively simplify formsets try django-extra-views


-- Clive

Prashanth Patelc

não lida,
28 de fev. de 2022, 11:27:5928/02/2022
para django...@googlegroups.com
Any example?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Clive Bruton

não lida,
28 de fev. de 2022, 12:08:3228/02/2022
para django...@googlegroups.com

On 28 Feb 2022, at 16:24, Prashanth Patelc wrote:

> Any example?

Just read the django-extra-views documentation. Essentially a formset
can be as simple to use as any of the built-in class-based views, eg:

from extra_views import InlineFormSetView

class EditContactAddresses(InlineFormSetView):
model = Contact
inline_model = Address
template_name = …


https://django-extra-views.readthedocs.io/en/latest/pages/formset-
views.html#inlineformsetview


-- Clive

Ryan Nowakowski

não lida,
9 de mar. de 2022, 18:55:1809/03/2022
para django...@googlegroups.com
The WQ project uses the Entity-Attribute-Value data model:

https://v1.wq.io/1.2/docs/eav-vs-relational

Derek

não lida,
11 de mar. de 2022, 00:48:5711/03/2022
para Django users
I'm not quite sure how these requirements have arisen as you have not provided any context as to the actual user or business needs.  In my experience,  most businesses and science organisations  understand very clearly what kinds of data they need to store and what they need to do with that data.   This makes it possible for the developers to design and  implement well-structured SQL  databases.

If,  for some reason, this is really not your use case then, as the other commenters have suggested,  it's likely that Django is not a good fit for your needs.  Perhaps you should consider a NoSQL  solution (https://www.mongodb.com/nosql-explained/when-to-use-nosql) instead;  and explore the use of  its associated technologies which can meet your stated requirements.

Joel Tanko

não lida,
14 de mar. de 2022, 09:41:3314/03/2022
para django...@googlegroups.com
If I understand correctly you're trying to give the user the power to create tables from the front end by saving his params to the database and using that data to create a table in another or the same  database, I tried doing the same with forms here's a tweak, hope it's what you're looking for or at least a step in the right direction. 

#models.py


Model = models.Model

class DynamicModel(Model):
    name = models.CharField(max_length=100)
    fields = models.ManyToManyField("Field", blank=True)

    def get_data(self, **kwargs) :
        # you'd probably want to do some 
           kind of db query here to postgres 
        using a Python wrapper. 
       #... cursor.execute("select * from %s" % self.name)
      # assuming that you've instantiated a postgres db cursor 

class Field(Model):
     name = models.CharField(max_length=100)
     field_type = models.CharField(max_length=100, 
    choices=(("integer", "Integer"), ("char", "char" ) )






--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
Responder a todos
Responder ao autor
Encaminhar
0 nova mensagem