Re: Displaying a custom field (PickledObjectField) in the admin

2013-09-10 Thread Paul
If you just want to see (read) the contents you could do this:

class Example(models.Model):
value = PickledObjectField()

def value_unpacked(self):
return u'{value}'.format(value=self.value)
filter_link.allow_tags = True

class ExampleAdmin(admin.ModelAdmin):
list_display = ('id', 'value_unpacked',)
 
Actually modifying it is obviously more difficult as it can be ... anything 
indeed

Paul

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


RE: Displaying a custom field (PickledObjectField) in the admin

2012-10-24 Thread lacrymol...@gmail.com

The short of it is that you should probably subclass the picklefield to add 
some new validation (basically is_integer_two_tuple_list), and write a custom 
widget for it that does what you want on the html side. The long of it needs 
not being written from a phone

-Mensaje original-
De: Alphydan
Enviados:  24/10/2012 19:58:29
Asunto:  Re: Displaying a custom field (PickledObjectField) in the admin

Hi Tomas & John,

Thank you for your reply.  Basically I'm trying to save curves which I 
chose to format as:
[[0,0],[1,0],[2,1],[3,1], ... ,[40,0]]

To see what I tried before (models, etc) you can see the stackoverflow 
question<http://stackoverflow.com/questions/13034922/storing-a-curve-in-a-django-model-as-manytomany>I
 asked previously.
Some people there suggested the django-picklefield so I implemented it but 
couldn't get the admin to work.
Unfortunately I would eventually need users to put in numbers in a template.

For the moment I'm just saving a TextField and doing some pretty coarse and 
inelegant validation + assuming we enter the curves in the admin.

def save(self, *args, **kwargs):
pc = self.my_power_curve
if pc[0]!='[':
pc = 'error. no initial [ --- ' + pc
self.my_power_curve = pc
elif pc[-1] != ']':
pc = 'error. no final ] --- ' + pc
self.my_power_curve = pc
elif  pc.count('[') != 42 or pc.count(']') !=42:
pc = 'error. 41 pairs [,] are required or too many brackets --- 
' + pc
self.my_power_curve = pc
elif  len(pc)>362:
pc = 'error. too many items --- ' + pc
self.my_power_curve = pc
elif pc.count('(') != 0 or pc.count(')') != 0:
pc = 'error. only "[" and "]" brackets allowed --- ' + pc
self.my_power_curve = pc
else:
pass
return super(SomeClass, self).save(*args, **kwargs)


Ideally I would create form with say 41 little fields:
value 1 = [  ]
value 2 = [  ]
value 3 = [  ]
...
value 41 = [  ]

and when the users completes *some of them*, I save it as a string:
"[[0,0],[1,1],[2,3],[10,20],[20,20],[40,0]]"

Eventually I want to retrieve them and calculate things (like area under 
the curve or make a graph).

Any ideas are appreciated,

Thank you,
Alvaro

On Wednesday, 24 October 2012 20:14:16 UTC+1, Tomas Neme wrote:
>
> Just by the way, I'm looking at django-picklefield code and README 
> https://github.com/gintas/django-picklefield and it says NOTHING about 
> a widget, or an admin representation, so.. maybe it's not DESIGNED to 
> be shown on the admin? it'd make sense, too, since it's.. well, it can 
> be ANYTHING 
>
> On Wed, Oct 24, 2012 at 3:03 PM, Tomas Neme > 
> wrote: 
> > maybe restate the problem, give some more code, show your models, and 
> > your admin files, and someone may be able to help a little 
> > 
> > -- 
> > "The whole of Japan is pure invention. There is no such country, there 
> > are no such people" --Oscar Wilde 
> > 
> > |_|0|_| 
> > |_|_|0| 
> > |0|0|0| 
> > 
> > (\__/) 
> > (='.'=)This is Bunny. Copy and paste bunny 
> > (")_(") to help him gain world domination. 
>
>
>
> -- 
> "The whole of Japan is pure invention. There is no such country, there 
> are no such people" --Oscar Wilde 
>
> |_|0|_| 
> |_|_|0| 
> |0|0|0| 
>
> (\__/) 
> (='.'=)This is Bunny. Copy and paste bunny 
> (")_(") to help him gain world domination. 
>

-- 
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/-/6RtZPEgjgFsJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Displaying a custom field (PickledObjectField) in the admin

2012-10-24 Thread Alphydan
Hi Tomas & John,

Thank you for your reply.  Basically I'm trying to save curves which I 
chose to format as:
[[0,0],[1,0],[2,1],[3,1], ... ,[40,0]]

To see what I tried before (models, etc) you can see the stackoverflow 
questionI
 asked previously.
Some people there suggested the django-picklefield so I implemented it but 
couldn't get the admin to work.
Unfortunately I would eventually need users to put in numbers in a template.

For the moment I'm just saving a TextField and doing some pretty coarse and 
inelegant validation + assuming we enter the curves in the admin.

def save(self, *args, **kwargs):
pc = self.my_power_curve
if pc[0]!='[':
pc = 'error. no initial [ --- ' + pc
self.my_power_curve = pc
elif pc[-1] != ']':
pc = 'error. no final ] --- ' + pc
self.my_power_curve = pc
elif  pc.count('[') != 42 or pc.count(']') !=42:
pc = 'error. 41 pairs [,] are required or too many brackets --- 
' + pc
self.my_power_curve = pc
elif  len(pc)>362:
pc = 'error. too many items --- ' + pc
self.my_power_curve = pc
elif pc.count('(') != 0 or pc.count(')') != 0:
pc = 'error. only "[" and "]" brackets allowed --- ' + pc
self.my_power_curve = pc
else:
pass
return super(SomeClass, self).save(*args, **kwargs)


Ideally I would create form with say 41 little fields:
value 1 = [  ]
value 2 = [  ]
value 3 = [  ]
...
value 41 = [  ]

and when the users completes *some of them*, I save it as a string:
"[[0,0],[1,1],[2,3],[10,20],[20,20],[40,0]]"

Eventually I want to retrieve them and calculate things (like area under 
the curve or make a graph).

Any ideas are appreciated,

Thank you,
Alvaro

On Wednesday, 24 October 2012 20:14:16 UTC+1, Tomas Neme wrote:
>
> Just by the way, I'm looking at django-picklefield code and README 
> https://github.com/gintas/django-picklefield and it says NOTHING about 
> a widget, or an admin representation, so.. maybe it's not DESIGNED to 
> be shown on the admin? it'd make sense, too, since it's.. well, it can 
> be ANYTHING 
>
> On Wed, Oct 24, 2012 at 3:03 PM, Tomas Neme > 
> wrote: 
> > maybe restate the problem, give some more code, show your models, and 
> > your admin files, and someone may be able to help a little 
> > 
> > -- 
> > "The whole of Japan is pure invention. There is no such country, there 
> > are no such people" --Oscar Wilde 
> > 
> > |_|0|_| 
> > |_|_|0| 
> > |0|0|0| 
> > 
> > (\__/) 
> > (='.'=)This is Bunny. Copy and paste bunny 
> > (")_(") to help him gain world domination. 
>
>
>
> -- 
> "The whole of Japan is pure invention. There is no such country, there 
> are no such people" --Oscar Wilde 
>
> |_|0|_| 
> |_|_|0| 
> |0|0|0| 
>
> (\__/) 
> (='.'=)This is Bunny. Copy and paste bunny 
> (")_(") to help him gain world domination. 
>

-- 
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/-/6RtZPEgjgFsJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Displaying a custom field (PickledObjectField) in the admin

2012-10-24 Thread Tomas Neme
Just by the way, I'm looking at django-picklefield code and README
https://github.com/gintas/django-picklefield and it says NOTHING about
a widget, or an admin representation, so.. maybe it's not DESIGNED to
be shown on the admin? it'd make sense, too, since it's.. well, it can
be ANYTHING

On Wed, Oct 24, 2012 at 3:03 PM, Tomas Neme  wrote:
> maybe restate the problem, give some more code, show your models, and
> your admin files, and someone may be able to help a little
>
> --
> "The whole of Japan is pure invention. There is no such country, there
> are no such people" --Oscar Wilde
>
> |_|0|_|
> |_|_|0|
> |0|0|0|
>
> (\__/)
> (='.'=)This is Bunny. Copy and paste bunny
> (")_(") to help him gain world domination.



-- 
"The whole of Japan is pure invention. There is no such country, there
are no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Displaying a custom field (PickledObjectField) in the admin

2012-10-24 Thread Tomas Neme
maybe restate the problem, give some more code, show your models, and
your admin files, and someone may be able to help a little

-- 
"The whole of Japan is pure invention. There is no such country, there
are no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Displaying a custom field (PickledObjectField) in the admin

2012-10-24 Thread John DeRosa
Nope, I didn't find a solution. I moved on to another issue and never got back 
to this. We just learned to work around this, I'm semi-ashamed to say.

John

On Oct 23, 2012, at 2:29 PM, Alphydan  wrote:

> I have the same problem (on ubuntu, python 2.7, django 1.4, 
> django-picklefield 0.2.1) ... does anybody have any insight?
> John, did you find a solution?
> 
> Thank you. 
> 
> On Thursday, 8 April 2010 19:30:20 UTC+1, John DeRosa wrote:
> Hello Djangonauts,
> 
> I'm doing something wrong, but I just can't see it!
> 
> My problem is that a custom model field isn't being displayed in the Admin 
> interface.
> 
> I'm running OS X 10.6.3, Python 2.6, and Django 1.1.1. I installed 
> django-picklefield 0.1.5 from PyPi, and I'm trying to use it in a database 
> model. I defined a couple of custom PickledObjectField fields. They show up 
> in the Admin model docs as being of type "Text", but they *don't* show up in 
> the Admin when I add or change a row.
> 
> Here's what I'm doing. What am I doing wrong?
> 
> John
> 
> --
> 
> In models.py:
> 
> from picklefield.fields import PickledObjectField
> 
> class LayoutTemplate(models.Model):
> [snip]
> attachment_points = PickledObjectField(help_text="A list of 
> TemplateAttachmentPoints")
> placed_objects = PickledObjectField(blank=True,
> help_text="A list of objects placed 
> on this template")
> # These LayoutObjects are allowed on this template.
> allowed_objects = PickledObjectField(help_text="A list of allowed 
> objects.")
> 
> def __unicode__(self):
> return u"%s" % self.name
> 
> 
> In admin.py:
> 
> from hosted.models import LayoutTemplate
> from django.contrib import admin
> admin.site.register(LayoutTemplate)
> 
> 
> 
> 
> -- 
> 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/-/QHA-yQ1spEIJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Displaying a custom field (PickledObjectField) in the admin

2012-10-23 Thread Alphydan
I have the same problem (on ubuntu, python 2.7, django 1.4, 
django-picklefield 0.2.1) ... does anybody have any insight?
John, did you find a solution?

Thank you. 

On Thursday, 8 April 2010 19:30:20 UTC+1, John DeRosa wrote:
>
> Hello Djangonauts,
>
> I'm doing something wrong, but I just can't see it!
>
> My problem is that a custom model field isn't being displayed in the Admin 
> interface.
>
> I'm running OS X 10.6.3, Python 2.6, and Django 1.1.1. I installed 
> django-picklefield 0.1.5 from PyPi, and I'm trying to use it in a database 
> model. I defined a couple of custom PickledObjectField fields. They show up 
> in the Admin model docs as being of type "Text", but they *don't* show up 
> in the Admin when I add or change a row.
>
> Here's what I'm doing. What am I doing wrong?
>
> John
>
> --
>
> In models.py:
>
> from picklefield.fields import PickledObjectField
>
> class LayoutTemplate(models.Model):
> [snip]
> attachment_points = PickledObjectField(help_text="A list of 
> TemplateAttachmentPoints")
> placed_objects = PickledObjectField(blank=True,
> help_text="A list of objects 
> placed on this template")
> # These LayoutObjects are allowed on this template.
> allowed_objects = PickledObjectField(help_text="A list of allowed 
> objects.")
>
> def __unicode__(self):
> return u"%s" % self.name
>
>
> In admin.py:
>
> from hosted.models import LayoutTemplate
> from django.contrib import admin
> admin.site.register(LayoutTemplate)
>
>
>
>

-- 
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/-/QHA-yQ1spEIJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.