how to auto-populate(auto-update) model's field(s) via custom button or on Save

45 views
Skip to first unread message

Andriyko

unread,
Nov 24, 2012, 7:40:58 PM11/24/12
to django...@googlegroups.com
Hello,

Please give an advice and some examples on how can I do the following.
1. I need to fetch some data (list of items) from external url and save that list into the field of the, say Model1(possible?)
The problem is not how to fetch, but how to save.
2. This should be done dynamically from admin add/change Model1 page using custom button or on Save.
3. Currently I use another Model2 to store that list(ManyToMany). Is it possible to store that list as field(and show these items on the Model's page) without Model2 so that I can use items of that list in a template?

In short, I want to be able to auto-fill some field of the model on Save or/and with custom button. Possible?

Thanks


Sergiy Khohlov

unread,
Nov 26, 2012, 7:37:31 AM11/26/12
to django...@googlegroups.com
>>> import httplib
>>> myhost = httplib.HTTPConnection('www.google.com')
>>> myhost.request("GET")
>>> googleanswer = myhost.getresponse()
>>> print googleanswer.read()
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.com.ua/">here</A>.
</BODY></HTML>

>>>


Need more ?


2012/11/25 Andriyko <ahry...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/ZINp_t_15zAJ.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

Andriyko

unread,
Nov 26, 2012, 1:38:18 PM11/26/12
to django...@googlegroups.com
The problem is not how to fetch, but how to save.

Sergiy Khohlov

unread,
Nov 26, 2012, 3:59:08 PM11/26/12
to django...@googlegroups.com
1. You dont need ManyToMany field
class urlclass(models.Model):
url =models.CharField()
class itemclass(models.Model):
url = models.ForeignKey(urlclass)
myitem = models.CharField()

#somewhere in view
def saveitems(url, itemlist):
for item in itemlist:
item = itemclass(url= urlclass.objects.get(url=url), myitem=item)
item.save()

or something like that :-)
2012/11/26 Andriyko <ahry...@gmail.com>:
> https://groups.google.com/d/msg/django-users/-/hoO6KnjrjZkJ.

Andriy Hrytskiv

unread,
Nov 27, 2012, 2:23:10 AM11/27/12
to django...@googlegroups.com
Thanks. Will try.
Reply all
Reply to author
Forward
0 new messages