Re: Updating django database

2018-06-02 Thread 'Anthony Flury' via Django users

Is this a new or a update from the front end ?

If new :
 1 Extract json using : data = json.load( request.POST['json'] - 
this converts data to a dictionary (assuming that the json is in the 
'json' field in the message.

 2 Validate as necessary
 3 Create instance : instance = Patient.create(**data),
    instance.save()

if an update to an existing instance :
 1 Extract json using : data = json.load( request.POST['json'] - 
this converts data to a dictionary (assuming that the json is in the 
'json' field in the message.

 2 Validate as necessary
 3 Update :
            for field, value in data.items():
  setattr(instance, field, value)

   instance.save()

        Assuming that instances is the Patient record to be updated.

I hope this helps.


On 29/05/18 12:37, Albin Antony wrote:

Hello guys,
Sorry about the above no subject mail
I am getting a json string(json_string) from frontend. How can we 
update the django database in views.py. Below is my models.py.

models.py

class Patient(models.Model):
    patient_id = models.CharField(primary_key=True, max_length=200)
    patient_age = models.CharField(max_length=200)
    patient_name = models.CharField(max_length=200)
    patient_refby = models.CharField(max_length=200)
    patient_gender = models.CharField(max_length=20,
default=Gender.UNKNOWN.value)


--
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+unsubscr...@googlegroups.com 
.
To post to this group, send email to django-users@googlegroups.com 
.

Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEohp0dkVzwRZWe9ig8cWWVyXq08K_qndfVmSpj8AM9Zxgaf-Q%40mail.gmail.com 
.

For more options, visit https://groups.google.com/d/optout.



--
--
Anthony Flury
email : *anthony.fl...@btinternet.com*
Twitter : *@TonyFlury *

--
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/24980dc2-6173-decd-67b6-871ef0ef9d3f%40btinternet.com.
For more options, visit https://groups.google.com/d/optout.


Re: Updating django database

2018-06-02 Thread Albin Antony
For updating multiple models at the same time, Should we create multiple
instances?

On Sat, Jun 2, 2018 at 6:19 PM, 'Anthony Flury' via Django users <
django-users@googlegroups.com> wrote:

> Is this a new or a update from the front end ?
>
> If new :
>  1 Extract json using : data = json.load( request.POST['json'] - this
> converts data to a dictionary (assuming that the json is in the 'json'
> field in the message.
>  2 Validate as necessary
>  3 Create instance : instance = Patient.create(**data),
> instance.save()
>
> if an update to an existing instance :
>  1 Extract json using : data = json.load( request.POST['json'] - this
> converts data to a dictionary (assuming that the json is in the 'json'
> field in the message.
>  2 Validate as necessary
>  3 Update :
> for field, value in data.items():
>   setattr(instance, field, value)
>
>instance.save()
>
> Assuming that instances is the Patient record to be updated.
>
> I hope this helps.
>
>
>
> On 29/05/18 12:37, Albin Antony wrote:
>
>> Hello guys,
>> Sorry about the above no subject mail
>> I am getting a json string(json_string) from frontend. How can we update
>> the django database in views.py. Below is my models.py.
>> models.py
>>
>> class Patient(models.Model):
>> patient_id = models.CharField(primary_key=True, max_length=200)
>> patient_age = models.CharField(max_length=200)
>> patient_name = models.CharField(max_length=200)
>> patient_refby = models.CharField(max_length=200)
>> patient_gender = models.CharField(max_length=20,
>> default=Gender.UNKNOWN.value)
>>
>>
>> --
>> 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+unsubscr...@googlegroups.com > django-users+unsubscr...@googlegroups.com>.
>> To post to this group, send email to django-users@googlegroups.com
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/CAEohp0dkVzwRZWe9ig8cWWVyXq08K_
>> qndfVmSpj8AM9Zxgaf-Q%40mail.gmail.com > sgid/django-users/CAEohp0dkVzwRZWe9ig8cWWVyXq08K_
>> qndfVmSpj8AM9Zxgaf-Q%40mail.gmail.com?utm_medium=email&utm_source=footer
>> >.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> --
> --
> Anthony Flury
> email : *anthony.fl...@btinternet.com*
> Twitter : *@TonyFlury *
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/ms
> gid/django-users/24980dc2-6173-decd-67b6-871ef0ef9d3f%40btinternet.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEohp0c2gUaC4hCjoxYVY7DRFopPbF88R4D_2HEzPGizL7FBoQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Updating django database

2018-06-02 Thread Melvyn Sopacua
On zaterdag 2 juni 2018 15:12:08 CEST Albin Antony wrote:
> For updating multiple models at the same time, Should we create multiple
> instances?

Multiple models (Patient and Medication) or multiple instances of the same 
model (more than one Patient)?

The later can be done with a single manager operation. The first cannot.

-- 
Melvyn Sopacua

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1591788.fE9Xf09d5R%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Updating django database

2018-06-02 Thread Albin Antony
Can the first be done if there is a relation between the models?


On Sat, Jun 2, 2018 at 7:49 PM, Melvyn Sopacua 
wrote:

> On zaterdag 2 juni 2018 15:12:08 CEST Albin Antony wrote:
> > For updating multiple models at the same time, Should we create multiple
> > instances?
>
> Multiple models (Patient and Medication) or multiple instances of the same
> model (more than one Patient)?
>
> The later can be done with a single manager operation. The first cannot.
>
> --
> Melvyn Sopacua
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/1591788.fE9Xf09d5R%40fritzbook.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEohp0e1PtAC4M8Um97%3DPmpT6M-R%3D%3D%2BuE6X%2Bs0HJj%3DGTV_jVug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Updating django database

2018-06-02 Thread 'Anthony Flury' via Django users

Is this a new or a update from the front end ?

If new :
 1 Extract json using : data = json.load( request.POST['json'] - 
this converts data to a dictionary (assuming that the json is in the 
'json' field in the message.

 2 Validate as necessary
 3 Create instance : instance = Patient.create(**data),
    instance.save()

if an update to an existing instance :
 1 Extract json using : data = json.load( request.POST['json'] - 
this converts data to a dictionary (assuming that the json is in the 
'json' field in the message.

 2 Validate as necessary
 3 Update :
            for field, value in data.items():
  setattr(instance, field, value)

   instance.save()

        Assuming that instance


On 29/05/18 12:37, Albin Antony wrote:

Hello guys,
Sorry about the above no subject mail
I am getting a json string(json_string) from frontend. How can we 
update the django database in views.py. Below is my models.py.

models.py

class Patient(models.Model):
    patient_id = models.CharField(primary_key=True, max_length=200)
    patient_age = models.CharField(max_length=200)
    patient_name = models.CharField(max_length=200)
    patient_refby = models.CharField(max_length=200)
    patient_gender = models.CharField(max_length=20,
default=Gender.UNKNOWN.value)


--
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+unsubscr...@googlegroups.com 
.
To post to this group, send email to django-users@googlegroups.com 
.

Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEohp0dkVzwRZWe9ig8cWWVyXq08K_qndfVmSpj8AM9Zxgaf-Q%40mail.gmail.com 
.

For more options, visit https://groups.google.com/d/optout.



--
--
Anthony Flury
email : *anthony.fl...@btinternet.com*
Twitter : *@TonyFlury *

--
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/efdb4d8e-ece2-2d95-9210-277fcdac9c9e%40btinternet.com.
For more options, visit https://groups.google.com/d/optout.


Is it possible to instantiate a model (create an object) and flag the instance as unsaveable?

2018-06-02 Thread Bernd Wechner
I'd like to instantiate a model, and play around with it, but ensure it's 
never saved. At bare minimum instantiate it, play around with it then 
delete it, but ideally disable saving somehow. I imagine I can override 
save() on the instance, but am wondering if anyone has experience doing 
this or if there's a canonical method for doing it. I'll experiment but in 
the mean time fishing as I said for experience and any standard methods out 
there.

Regards,

Bernd.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c14ca134-cc54-498a-b5fa-78e80b768102%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is it possible to instantiate a model (create an object) and flag the instance as unsaveable?

2018-06-02 Thread James Bradshaw
Hey Bernd,

I'm curious about your use case. It's common to create a read-only database
user to make sure no data is modified, but I've never come across anything
at the instance/row level.

-Jimmy

On Sat, Jun 2, 2018, 8:14 PM Bernd Wechner  wrote:

> I'd like to instantiate a model, and play around with it, but ensure it's
> never saved. At bare minimum instantiate it, play around with it then
> delete it, but ideally disable saving somehow. I imagine I can override
> save() on the instance, but am wondering if anyone has experience doing
> this or if there's a canonical method for doing it. I'll experiment but in
> the mean time fishing as I said for experience and any standard methods out
> there.
>
> Regards,
>
> Bernd.
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c14ca134-cc54-498a-b5fa-78e80b768102%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADEEVemMcE0YMK74hUsbpUc9yDzdd33KMd%3DLgCEacnYoKN45Gw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is it possible to instantiate a model (create an object) and flag the instance as unsaveable?

2018-06-02 Thread James Schneider
On Sat, Jun 2, 2018, 6:14 PM Bernd Wechner  wrote:

> I'd like to instantiate a model, and play around with it, but ensure it's
> never saved. At bare minimum instantiate it, play around with it then
> delete it, but ideally disable saving somehow. I imagine I can override
> save() on the instance, but am wondering if anyone has experience doing
> this or if there's a canonical method for doing it. I'll experiment but in
> the mean time fishing as I said for experience and any standard methods out
> there.
>

One way to make an obvious indication that the model instance is read-only
is to use a proxy model of the original, with all the saving bits turned
off. Keeps a nice separation of code while utilizing inheritance, and
allows usage of the original/standard behavior.

IMO, overriding the save() method in the proxy model is probably the
cleanest way to prevent an accidental save by a signal, etc.

https://docs.djangoproject.com/en/dev/topics/db/models/#proxy-models

-James

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWEjN9M_pmquUpcTASKFtABiWzwtNrK0uHoLW%3D7CnAvpQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.