Re: Problem hiding fields from admin page based on another fields value

2014-05-30 Thread Hilde Rafaelsen
I get same error as before; 'NoneType' object has no attribute 'readiness' 
when I changed to your excample. I don't understand why this is not working 
for me, but for everyone else

Is it something I have forgot to import? I hope you can take a quick look 
at my uploaded files. Is it ok to just use get_form from the admin class 
directly, or do I need to create a Form class as well?



On Friday, May 30, 2014 2:35:01 PM UTC+2, Timothy W. Cook wrote:
>
> try this get_form:
>
> def get_form(self, request, obj=None, **kwargs):
>  if obj.readiness:
>  self.exclude = ("readinessDescription", )
>  return super(RequestForChangeAdmin, self).get_form(request, obj, 
> **kwargs)
>
>
> I have never used 'exclude' but it looks like yours should work. 
>
>
> On Fri, May 30, 2014 at 9:18 AM, Hilde Rafaelsen  > wrote:
>
>> Thanx,
>>
>> I now changed my if test to just if obj.readines but then I get the error 
>> message 'NoneType' object has no attribute 'readiness'
>>
>>
>> I have tried with several fields from my model, but I always get this 
>> error. I guess it must be something essential I am doing wrong here, since 
>> my obj seems to be none always...
>>
>> I have get_form inside my modelAdmin class.
>>
>>
>> On Friday, May 30, 2014 2:06:59 PM UTC+2, Timothy W. Cook wrote:
>>
>>> What do you mean by tri-state?
>>>
>>> You are using a field that allows three states: TRUE, FALSE and NULL. 
>>>
>>> If I understand the model, readiness would either be TRUE or FALSE.  But 
>>> if you do not want to change your field type to:
>>> readiness = models.BooleanField("Readiness", blank=True)
>>>  
>>> then try changing:
>>> if obj.readiness == True:
>>>
>>> to:
>>>
>>> if obj.readiness and obj.readiness == True:
>>>
>>> or just:
>>> if obj.readiness:
>>>
>>> Will give you the same result.
>>>
>>> This way if it doesn't exist it will not fail on the  '== TRUE' test. 
>>>
>>>  
>>>
>>> On Fri, May 30, 2014 at 8:49 AM, Hilde Rafaelsen  
>>> wrote:
>>>
  Hi,

  

 Thanks for the response.

  

 What do you mean by tri-state?

  

 I changed my get_form to this:

 def get_form(self, request, obj=None, **kwargs):

form = super(RequestForChangeAdmin, 
 self).get_form(request, obj, **kwargs)

if obj:

if obj.readiness == 
 True:


 self.exclude = ("readinessDescription", )

form = 
 super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)

return form

  

 No my code run without errors, but nothing happpends though ☺

  

 I have tried to change the readiness filds to yes and no, but the field 
 readiness descriptions is always displayed. Maybe it is not possibly to 
 get 
 a fields attribute value from admin before the admin form is posted or 
 stored in database? Do you know?

  

 Regards,

 Hilde from Norway

 On Friday, May 30, 2014 12:57:19 PM UTC+2, Hilde Rafaelsen wrote:
>
> Hello,
>
> In my django admin page I want to hide some filelds from users if a 
> special field value is set. I have tried different solutions to solve my 
> problem but is stucked and hope someone can help me,
>
> If you look at my model I want to hide the field readinessDescription 
> if readiness value is False (no), when the user log into admin page. 
>
> In model.py:
> class RequestForChange (models.Model):
>  rfc = models.AutoField (primary_key=True, help_text="This is the 
> grey text")
> heading = models.CharField("Heading", max_length=50)
>readiness = models.NullBooleanField("Readiness", blank=True, 
> null=True)
>readinessDescription = models.TextField("Description of 
> readiness", max_length=250, blank=True, null=True) 
>
>
> I found some hints on the web about using get_form from my 
> RequestForChangeAdmin page, but it won't work because i get this error 
> 'NoneType' object has no attribute 'readiness'
>
>
> Here is what I have in admin.py:
>
> class RequestForChangeAdmin(admin.ModelAdmin):
> formfield_overrides = {
>  models.ManyToManyField: {'widget': CheckboxSelectMultiple},
> }
> list_display = ('rfc', 'heading', 'enviroment', 'status')
>  search_fields = ('changeId',)
> list_filter = ('enviroment', 'acceptAT', 'status')
>  date_hierarchy = 'criticalDate'
> inline = [RequestForChangeInline]
>   def get_form(self, request, obj=None, **kwargs):
> form = super(RequestForChangeAdmin, self).get_form(request, obj, 
> **kwargs)
>  print 

Re: Problem hiding fields from admin page based on another fields value

2014-05-30 Thread Timothy W. Cook
try this get_form:

def get_form(self, request, obj=None, **kwargs):
if obj.readiness:
self.exclude = ("readinessDescription", )
return super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)


I have never used 'exclude' but it looks like yours should work.


On Fri, May 30, 2014 at 9:18 AM, Hilde Rafaelsen 
wrote:

> Thanx,
>
> I now changed my if test to just if obj.readines but then I get the error
> message 'NoneType' object has no attribute 'readiness'
>
>
> I have tried with several fields from my model, but I always get this
> error. I guess it must be something essential I am doing wrong here, since
> my obj seems to be none always...
>
> I have get_form inside my modelAdmin class.
>
>
> On Friday, May 30, 2014 2:06:59 PM UTC+2, Timothy W. Cook wrote:
>
>> What do you mean by tri-state?
>>
>> You are using a field that allows three states: TRUE, FALSE and NULL.
>>
>> If I understand the model, readiness would either be TRUE or FALSE.  But
>> if you do not want to change your field type to:
>> readiness = models.BooleanField("Readiness", blank=True)
>>
>> then try changing:
>> if obj.readiness == True:
>>
>> to:
>>
>> if obj.readiness and obj.readiness == True:
>>
>> or just:
>> if obj.readiness:
>>
>> Will give you the same result.
>>
>> This way if it doesn't exist it will not fail on the  '== TRUE' test.
>>
>>
>>
>> On Fri, May 30, 2014 at 8:49 AM, Hilde Rafaelsen 
>> wrote:
>>
>>> Hi,
>>>
>>>
>>>
>>> Thanks for the response.
>>>
>>>
>>>
>>> What do you mean by tri-state?
>>>
>>>
>>>
>>> I changed my get_form to this:
>>>
>>> def get_form(self, request, obj=None, **kwargs):
>>>
>>>form = super(RequestForChangeAdmin,
>>> self).get_form(request, obj, **kwargs)
>>>
>>>if obj:
>>>
>>>if obj.readiness == True:
>>>
>>>
>>> self.exclude = ("readinessDescription", )
>>>
>>>form =
>>> super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>>>
>>>return form
>>>
>>>
>>>
>>> No my code run without errors, but nothing happpends though ☺
>>>
>>>
>>>
>>> I have tried to change the readiness filds to yes and no, but the field
>>> readiness descriptions is always displayed. Maybe it is not possibly to get
>>> a fields attribute value from admin before the admin form is posted or
>>> stored in database? Do you know?
>>>
>>>
>>>
>>> Regards,
>>>
>>> Hilde from Norway
>>>
>>> On Friday, May 30, 2014 12:57:19 PM UTC+2, Hilde Rafaelsen wrote:

 Hello,

 In my django admin page I want to hide some filelds from users if a
 special field value is set. I have tried different solutions to solve my
 problem but is stucked and hope someone can help me,

 If you look at my model I want to hide the field readinessDescription
 if readiness value is False (no), when the user log into admin page.

 In model.py:
 class RequestForChange (models.Model):
  rfc = models.AutoField (primary_key=True, help_text="This is the grey
 text")
 heading = models.CharField("Heading", max_length=50)
readiness = models.NullBooleanField("Readiness", blank=True,
 null=True)
readinessDescription = models.TextField("Description of
 readiness", max_length=250, blank=True, null=True)


 I found some hints on the web about using get_form from my
 RequestForChangeAdmin page, but it won't work because i get this error
 'NoneType' object has no attribute 'readiness'


 Here is what I have in admin.py:

 class RequestForChangeAdmin(admin.ModelAdmin):
 formfield_overrides = {
  models.ManyToManyField: {'widget': CheckboxSelectMultiple},
 }
 list_display = ('rfc', 'heading', 'enviroment', 'status')
  search_fields = ('changeId',)
 list_filter = ('enviroment', 'acceptAT', 'status')
  date_hierarchy = 'criticalDate'
 inline = [RequestForChangeInline]
   def get_form(self, request, obj=None, **kwargs):
 form = super(RequestForChangeAdmin, self).get_form(request, obj,
 **kwargs)
  print obj
 if obj.readiness == True:
 self.exclude = ("readinessDescription", )
  form = super(RequestForChangeAdmin, self).get_form(request, obj,
 **kwargs)
 return form

>>>  --
>>> 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 post to this group, send email to django...@googlegroups.com.
>>>
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/django-users/5bc768df-3a1c-4b53--2ec19b9c05f0%
>>> 40googlegroups.com
>>> 

Re: Problem hiding fields from admin page based on another fields value

2014-05-30 Thread Hilde Rafaelsen
I have uploaded my model and admin file and hope someone can tell me why I 
can't get my get_form method to work :)

Regards,
Hilde

>
>>  

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/494dcd61-e77f-4844-8243-d838169bea5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
from django.db import models
from django.contrib.auth.models import User
from django.forms import CheckboxSelectMultiple
from django.contrib import admin



class Enviroment (models.Model):
	enviroment = models.AutoField (primary_key=True)
	EnviromentName = models.CharField("Enviroment", max_length = 50)
	def __unicode__(self):
		return '%s' % (self.EnviromentName)

class ChangeType (models.Model):
	change = models.AutoField (primary_key=True)
	changeName = models.CharField(verbose_name="Type of change", max_length = 50)
	
	def __unicode__(self):
		return '%s' % (self.changeName)

	
class Status (models.Model):
	status = models.AutoField (primary_key=True)
	statusName = models.CharField("Status", max_length = 50)
	def __unicode__(self):
		return '%s' % (self.statusName)

class Resource (models.Model):
	resource = models.AutoField (primary_key=True)
	resourceFirstName = models.CharField("First name", max_length = 50)
	resourceLastName = models.CharField("Last name", max_length = 50)
	organization = models.CharField("Organization", max_length = 50)
	resourcePhone = models.IntegerField("Phone number")
	resourceRole = models.CharField("Role", max_length=50)
	def __unicode__(self):
		return '%s %s' % (self.resourceFirstName, self.resourceLastName)

class ReasonForChange(models.Model):
	reasonForChange = models.AutoField (primary_key=True)
	reasonForChangeName = models.CharField("Reason for change", max_length=50)
	def __unicode__(self):
		return '%s' % (self.reasonForChangeName)
		
class GoalOfChange (models.Model):
	goalOfChange = models.AutoField(primary_key=True)
	goalOfChangeName = models.CharField("Goal of change", max_length=50)
	def __unicode__(self):
		return '%s' % (self.goalOfChangeName)
	
	
class RequestForChange (models.Model):
	formfield_overrides  = {
models.ManyToManyField: {'widget': CheckboxSelectMultiple},
}
	One = '1'
	Two = '2'
	Three = '3'
	Four = '4'
	EFFECT_CHOICES = (
		(One, '1'),
		(Two, '2'),
		(Three, '3'),
		(Four, '4'),
)
	rfc = models.AutoField (primary_key=True, help_text="This is the grey text")
	user = models.ForeignKey(User, verbose_name="Change owner")
	changeId = models.IntegerField("Frontrange ID", blank=True, null=True)
	TFSId = models.IntegerField("TFS ID", blank=True, null=True)
	enviroment = models.ForeignKey(Enviroment, verbose_name="Enviroment")
	status = models.ForeignKey(Status, verbose_name="Status")
	heading = models.CharField("Heading", max_length=50)
	reasonForChange = models.ManyToManyField(ReasonForChange, verbose_name="Reason for change", blank=True, null=True)
	reasonForChange = models.ManyToManyField(ReasonForChange, verbose_name="Reason for change", blank=True, null=True)
	goalOfChange = models.ManyToManyField(GoalOfChange, verbose_name="Goal of change test",blank=True, null=True )
	rfcDateCreated = models.DateField("Date created")
	acceptAT = models.NullBooleanField("Is the change accepted by customer?", blank=True, null=True)
	testReport = models.NullBooleanField("Do we have a testreport?", blank=True, null=True)
	critical = models.NullBooleanField("Time critical", blank=True, null=True)
	criticalDate = models.DateField("Critical date", blank=True, null=True)
	CriticalDateDescription = models.TextField("Description", max_length=250, blank=True, null=True)
	effect = models.CharField(choices=EFFECT_CHOICES, verbose_name="Effect", max_length=2, blank=True, null=True)
	urgency = models.CharField(choices=EFFECT_CHOICES, verbose_name="Effect", max_length=2, blank=True, null=True)
	priority = models.IntegerField("Priority", blank=True, null=True)
	priorityComments = models.TextField("Comments", max_length=100, blank=True, null=True)
	budget = models.TextField("Description of budget", max_length=250, blank=True, null=True)
	estimatedTime = models.CharField("Estimated time for deploy of change", max_length=30, blank=True, null=True)
	changeType = models.ForeignKey(ChangeType, verbose_name="Type of change")
	resource = models.ManyToManyField(Resource, verbose_name="Responsible for change?", blank=True, null=True)
	stakeholder = models.ManyToManyField(Resource, related_name='stakeholder', verbose_name="Stakeholders", blank=True, null=True)
	effectOnEnviroments = models.ManyToManyField(Enviroment, related_name="EffectOnEnviroment", verbose_name="Enviroment 

Re: Problem hiding fields from admin page based on another fields value

2014-05-30 Thread Hilde Rafaelsen
Thanx,

I now changed my if test to just if obj.readines but then I get the error 
message 'NoneType' object has no attribute 'readiness'


I have tried with several fields from my model, but I always get this 
error. I guess it must be something essential I am doing wrong here, since 
my obj seems to be none always...

I have get_form inside my modelAdmin class.


On Friday, May 30, 2014 2:06:59 PM UTC+2, Timothy W. Cook wrote:
>
> What do you mean by tri-state?
>
> You are using a field that allows three states: TRUE, FALSE and NULL. 
>
> If I understand the model, readiness would either be TRUE or FALSE.  But 
> if you do not want to change your field type to:
> readiness = models.BooleanField("Readiness", blank=True)
>  
> then try changing:
> if obj.readiness == True:
>
> to:
>
> if obj.readiness and obj.readiness == True:
>
> or just:
> if obj.readiness:
>
> Will give you the same result.
>
> This way if it doesn't exist it will not fail on the  '== TRUE' test. 
>
>
>
> On Fri, May 30, 2014 at 8:49 AM, Hilde Rafaelsen  > wrote:
>
>> Hi,
>>
>>  
>>
>> Thanks for the response.
>>
>>  
>>
>> What do you mean by tri-state?
>>
>>  
>>
>> I changed my get_form to this:
>>
>> def get_form(self, request, obj=None, **kwargs):
>>
>>form = super(RequestForChangeAdmin, 
>> self).get_form(request, obj, **kwargs)
>>
>>if obj:
>>
>>if obj.readiness == True:
>>
>>
>> self.exclude = ("readinessDescription", )
>>
>>form = 
>> super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>>
>>return form
>>
>>  
>>
>> No my code run without errors, but nothing happpends though ☺
>>
>>  
>>
>> I have tried to change the readiness filds to yes and no, but the field 
>> readiness descriptions is always displayed. Maybe it is not possibly to get 
>> a fields attribute value from admin before the admin form is posted or 
>> stored in database? Do you know?
>>
>>  
>>
>> Regards,
>>
>> Hilde from Norway
>>
>> On Friday, May 30, 2014 12:57:19 PM UTC+2, Hilde Rafaelsen wrote:
>>>
>>> Hello,
>>>
>>> In my django admin page I want to hide some filelds from users if a 
>>> special field value is set. I have tried different solutions to solve my 
>>> problem but is stucked and hope someone can help me,
>>>
>>> If you look at my model I want to hide the field readinessDescription if 
>>> readiness value is False (no), when the user log into admin page. 
>>>
>>> In model.py:
>>> class RequestForChange (models.Model):
>>>  rfc = models.AutoField (primary_key=True, help_text="This is the grey 
>>> text")
>>> heading = models.CharField("Heading", max_length=50)
>>>readiness = models.NullBooleanField("Readiness", blank=True, 
>>> null=True)
>>>readinessDescription = models.TextField("Description of 
>>> readiness", max_length=250, blank=True, null=True) 
>>>
>>>
>>> I found some hints on the web about using get_form from my 
>>> RequestForChangeAdmin page, but it won't work because i get this error 
>>> 'NoneType' object has no attribute 'readiness'
>>>
>>>
>>> Here is what I have in admin.py:
>>>
>>> class RequestForChangeAdmin(admin.ModelAdmin):
>>> formfield_overrides = {
>>>  models.ManyToManyField: {'widget': CheckboxSelectMultiple},
>>> }
>>> list_display = ('rfc', 'heading', 'enviroment', 'status')
>>>  search_fields = ('changeId',)
>>> list_filter = ('enviroment', 'acceptAT', 'status')
>>>  date_hierarchy = 'criticalDate'
>>> inline = [RequestForChangeInline]
>>>   def get_form(self, request, obj=None, **kwargs):
>>> form = super(RequestForChangeAdmin, self).get_form(request, obj, 
>>> **kwargs)
>>>  print obj
>>> if obj.readiness == True:
>>> self.exclude = ("readinessDescription", )
>>>  form = super(RequestForChangeAdmin, self).get_form(request, obj, 
>>> **kwargs)
>>> return form
>>>
>>  -- 
>> 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 post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/5bc768df-3a1c-4b53--2ec19b9c05f0%40googlegroups.com
>>  
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
>
> 
> Timothy Cook
> LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
> MLHIM http://www.mlhim.org
>
> 

-- 
You received this 

Re: Problem hiding fields from admin page based on another fields value

2014-05-30 Thread Timothy W. Cook
Maybe it is not possibly to get a fields attribute value from admin before
the admin form is posted or stored in database? Do you know?

Yes, it is possible.  I use this to set which fields are readonly before
defining the fieldsets.  It works great.


def get_form(self, request, obj=None, **kwargs):
try:
if obj.published:
self.readonly_fields =
['prj_name','published','lang','schema_code','description','sem_attr','resource_uri','asserts',

'label','performer_p','function','mode','simple_function','simple_mode',]
except (AttributeError, TypeError) as e:
self.readonly_fields = ['published','schema_code']
return super(ParticipationAdmin, self).get_form(request, obj,
**kwargs)






On Fri, May 30, 2014 at 9:05 AM, Timothy W. Cook  wrote:

> What do you mean by tri-state?
>
> You are using a field that allows three states: TRUE, FALSE and NULL.
>
> If I understand the model, readiness would either be TRUE or FALSE.  But
> if you do not want to change your field type to:
> readiness = models.BooleanField("Readiness", blank=True)
>
> then try changing:
> if obj.readiness == True:
>
> to:
>
> if obj.readiness and obj.readiness == True:
>
> or just:
> if obj.readiness:
>
> Will give you the same result.
>
> This way if it doesn't exist it will not fail on the  '== TRUE' test.
>
>
>
> On Fri, May 30, 2014 at 8:49 AM, Hilde Rafaelsen 
> wrote:
>
>> Hi,
>>
>>
>>
>> Thanks for the response.
>>
>>
>>
>> What do you mean by tri-state?
>>
>>
>>
>> I changed my get_form to this:
>>
>> def get_form(self, request, obj=None, **kwargs):
>>
>>form = super(RequestForChangeAdmin,
>> self).get_form(request, obj, **kwargs)
>>
>>if obj:
>>
>>if obj.readiness == True:
>>
>>
>> self.exclude = ("readinessDescription", )
>>
>>form =
>> super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>>
>>return form
>>
>>
>>
>> No my code run without errors, but nothing happpends though ☺
>>
>>
>>
>> I have tried to change the readiness filds to yes and no, but the field
>> readiness descriptions is always displayed. Maybe it is not possibly to get
>> a fields attribute value from admin before the admin form is posted or
>> stored in database? Do you know?
>>
>>
>>
>> Regards,
>>
>> Hilde from Norway
>>
>> On Friday, May 30, 2014 12:57:19 PM UTC+2, Hilde Rafaelsen wrote:
>>>
>>> Hello,
>>>
>>> In my django admin page I want to hide some filelds from users if a
>>> special field value is set. I have tried different solutions to solve my
>>> problem but is stucked and hope someone can help me,
>>>
>>> If you look at my model I want to hide the field readinessDescription if
>>> readiness value is False (no), when the user log into admin page.
>>>
>>> In model.py:
>>> class RequestForChange (models.Model):
>>>  rfc = models.AutoField (primary_key=True, help_text="This is the grey
>>> text")
>>> heading = models.CharField("Heading", max_length=50)
>>>readiness = models.NullBooleanField("Readiness", blank=True,
>>> null=True)
>>>readinessDescription = models.TextField("Description of
>>> readiness", max_length=250, blank=True, null=True)
>>>
>>>
>>> I found some hints on the web about using get_form from my
>>> RequestForChangeAdmin page, but it won't work because i get this error
>>> 'NoneType' object has no attribute 'readiness'
>>>
>>>
>>> Here is what I have in admin.py:
>>>
>>> class RequestForChangeAdmin(admin.ModelAdmin):
>>> formfield_overrides = {
>>>  models.ManyToManyField: {'widget': CheckboxSelectMultiple},
>>> }
>>> list_display = ('rfc', 'heading', 'enviroment', 'status')
>>>  search_fields = ('changeId',)
>>> list_filter = ('enviroment', 'acceptAT', 'status')
>>>  date_hierarchy = 'criticalDate'
>>> inline = [RequestForChangeInline]
>>>   def get_form(self, request, obj=None, **kwargs):
>>> form = super(RequestForChangeAdmin, self).get_form(request, obj,
>>> **kwargs)
>>>  print obj
>>> if obj.readiness == True:
>>> self.exclude = ("readinessDescription", )
>>>  form = super(RequestForChangeAdmin, self).get_form(request, obj,
>>> **kwargs)
>>> return form
>>>
>>  --
>> 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.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/5bc768df-3a1c-4b53--2ec19b9c05f0%40googlegroups.com
>> 

Re: Problem hiding fields from admin page based on another fields value

2014-05-30 Thread Timothy W. Cook
What do you mean by tri-state?

You are using a field that allows three states: TRUE, FALSE and NULL.

If I understand the model, readiness would either be TRUE or FALSE.  But if
you do not want to change your field type to:
readiness = models.BooleanField("Readiness", blank=True)

then try changing:
if obj.readiness == True:

to:

if obj.readiness and obj.readiness == True:

or just:
if obj.readiness:

Will give you the same result.

This way if it doesn't exist it will not fail on the  '== TRUE' test.



On Fri, May 30, 2014 at 8:49 AM, Hilde Rafaelsen 
wrote:

> Hi,
>
>
>
> Thanks for the response.
>
>
>
> What do you mean by tri-state?
>
>
>
> I changed my get_form to this:
>
> def get_form(self, request, obj=None, **kwargs):
>
>form = super(RequestForChangeAdmin,
> self).get_form(request, obj, **kwargs)
>
>if obj:
>
>if obj.readiness == True:
>
>
> self.exclude = ("readinessDescription", )
>
>form =
> super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>
>return form
>
>
>
> No my code run without errors, but nothing happpends though ☺
>
>
>
> I have tried to change the readiness filds to yes and no, but the field
> readiness descriptions is always displayed. Maybe it is not possibly to get
> a fields attribute value from admin before the admin form is posted or
> stored in database? Do you know?
>
>
>
> Regards,
>
> Hilde from Norway
>
> On Friday, May 30, 2014 12:57:19 PM UTC+2, Hilde Rafaelsen wrote:
>>
>> Hello,
>>
>> In my django admin page I want to hide some filelds from users if a
>> special field value is set. I have tried different solutions to solve my
>> problem but is stucked and hope someone can help me,
>>
>> If you look at my model I want to hide the field readinessDescription if
>> readiness value is False (no), when the user log into admin page.
>>
>> In model.py:
>> class RequestForChange (models.Model):
>> rfc = models.AutoField (primary_key=True, help_text="This is the grey
>> text")
>> heading = models.CharField("Heading", max_length=50)
>>readiness = models.NullBooleanField("Readiness", blank=True,
>> null=True)
>>readinessDescription = models.TextField("Description of
>> readiness", max_length=250, blank=True, null=True)
>>
>>
>> I found some hints on the web about using get_form from my
>> RequestForChangeAdmin page, but it won't work because i get this error
>> 'NoneType' object has no attribute 'readiness'
>>
>>
>> Here is what I have in admin.py:
>>
>> class RequestForChangeAdmin(admin.ModelAdmin):
>> formfield_overrides = {
>> models.ManyToManyField: {'widget': CheckboxSelectMultiple},
>> }
>> list_display = ('rfc', 'heading', 'enviroment', 'status')
>> search_fields = ('changeId',)
>> list_filter = ('enviroment', 'acceptAT', 'status')
>> date_hierarchy = 'criticalDate'
>> inline = [RequestForChangeInline]
>>  def get_form(self, request, obj=None, **kwargs):
>> form = super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>>  print obj
>> if obj.readiness == True:
>> self.exclude = ("readinessDescription", )
>> form = super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>> return form
>>
>  --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5bc768df-3a1c-4b53--2ec19b9c05f0%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 


Timothy Cook
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
MLHIM http://www.mlhim.org

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B%3DOU3Xb87s3nHy%2BKPb_UEbVsSsrFd7Z5-OfisDKgN1gD6R6aQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem hiding fields from admin page based on another fields value

2014-05-30 Thread Hilde Rafaelsen
and one more thing. My obj is always none (empty), why is that?



On Friday, May 30, 2014 1:49:12 PM UTC+2, Hilde Rafaelsen wrote:
>
> Hi,
>
>  
>
> Thanks for the response.
>
>  
>
> What do you mean by tri-state?
>
>  
>
> I changed my get_form to this:
>
> def get_form(self, request, obj=None, **kwargs):
>
>form = super(RequestForChangeAdmin, 
> self).get_form(request, obj, **kwargs)
>
>if obj:
>
>if obj.readiness == True:
>
>
> self.exclude = ("readinessDescription", )
>
>form = 
> super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>
>return form
>
>  
>
> No my code run without errors, but nothing happpends though ☺
>
>  
>
> I have tried to change the readiness filds to yes and no, but the field 
> readiness descriptions is always displayed. Maybe it is not possibly to get 
> a fields attribute value from admin before the admin form is posted or 
> stored in database? Do you know?
>
>  
>
> Regards,
>
> Hilde from Norway
>
> On Friday, May 30, 2014 12:57:19 PM UTC+2, Hilde Rafaelsen wrote:
>>
>> Hello,
>>
>> In my django admin page I want to hide some filelds from users if a 
>> special field value is set. I have tried different solutions to solve my 
>> problem but is stucked and hope someone can help me,
>>
>> If you look at my model I want to hide the field readinessDescription if 
>> readiness value is False (no), when the user log into admin page. 
>>
>> In model.py:
>> class RequestForChange (models.Model):
>> rfc = models.AutoField (primary_key=True, help_text="This is the grey 
>> text")
>> heading = models.CharField("Heading", max_length=50)
>>readiness = models.NullBooleanField("Readiness", blank=True, 
>> null=True)
>>readinessDescription = models.TextField("Description of 
>> readiness", max_length=250, blank=True, null=True) 
>>
>>
>> I found some hints on the web about using get_form from my 
>> RequestForChangeAdmin page, but it won't work because i get this error 
>> 'NoneType' object has no attribute 'readiness'
>>
>>
>> Here is what I have in admin.py:
>>
>> class RequestForChangeAdmin(admin.ModelAdmin):
>> formfield_overrides = {
>> models.ManyToManyField: {'widget': CheckboxSelectMultiple},
>> }
>> list_display = ('rfc', 'heading', 'enviroment', 'status')
>> search_fields = ('changeId',)
>> list_filter = ('enviroment', 'acceptAT', 'status')
>> date_hierarchy = 'criticalDate'
>> inline = [RequestForChangeInline]
>>  def get_form(self, request, obj=None, **kwargs):
>> form = super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>>  print obj
>> if obj.readiness == True:
>> self.exclude = ("readinessDescription", )
>> form = super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>> return form
>>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6896b357-475c-4c5a-bb56-fafd283b9ff3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem hiding fields from admin page based on another fields value

2014-05-30 Thread Hilde Rafaelsen


Hi,

 

Thanks for the response.

 

What do you mean by tri-state?

 

I changed my get_form to this:

def get_form(self, request, obj=None, **kwargs):

   form = super(RequestForChangeAdmin, 
self).get_form(request, obj, **kwargs)

   if obj:

   if obj.readiness == True:

   self.exclude 
= ("readinessDescription", )

   form = 
super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)

   return form

 

No my code run without errors, but nothing happpends though ☺

 

I have tried to change the readiness filds to yes and no, but the field 
readiness descriptions is always displayed. Maybe it is not possibly to get 
a fields attribute value from admin before the admin form is posted or 
stored in database? Do you know?

 

Regards,

Hilde from Norway

On Friday, May 30, 2014 12:57:19 PM UTC+2, Hilde Rafaelsen wrote:
>
> Hello,
>
> In my django admin page I want to hide some filelds from users if a 
> special field value is set. I have tried different solutions to solve my 
> problem but is stucked and hope someone can help me,
>
> If you look at my model I want to hide the field readinessDescription if 
> readiness value is False (no), when the user log into admin page. 
>
> In model.py:
> class RequestForChange (models.Model):
> rfc = models.AutoField (primary_key=True, help_text="This is the grey 
> text")
> heading = models.CharField("Heading", max_length=50)
>readiness = models.NullBooleanField("Readiness", blank=True, 
> null=True)
>readinessDescription = models.TextField("Description of readiness", 
> max_length=250, blank=True, null=True) 
>
>
> I found some hints on the web about using get_form from my 
> RequestForChangeAdmin page, but it won't work because i get this error 
> 'NoneType' object has no attribute 'readiness'
>
>
> Here is what I have in admin.py:
>
> class RequestForChangeAdmin(admin.ModelAdmin):
> formfield_overrides = {
> models.ManyToManyField: {'widget': CheckboxSelectMultiple},
> }
> list_display = ('rfc', 'heading', 'enviroment', 'status')
> search_fields = ('changeId',)
> list_filter = ('enviroment', 'acceptAT', 'status')
> date_hierarchy = 'criticalDate'
> inline = [RequestForChangeInline]
>  def get_form(self, request, obj=None, **kwargs):
> form = super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>  print obj
> if obj.readiness == True:
> self.exclude = ("readinessDescription", )
> form = super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
> return form
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5bc768df-3a1c-4b53--2ec19b9c05f0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem hiding fields from admin page based on another fields value

2014-05-30 Thread Timothy W. Cook
Is 'readiness' really a tri-state flag?

Anyway you may want to test if obj.readiness exists, and is TRUE.

if obj.readiness and obj.readiness == TRUE:


HTH,
Tim



On Fri, May 30, 2014 at 7:57 AM, Hilde Rafaelsen 
wrote:

> Hello,
>
> In my django admin page I want to hide some filelds from users if a
> special field value is set. I have tried different solutions to solve my
> problem but is stucked and hope someone can help me,
>
> If you look at my model I want to hide the field readinessDescription if
> readiness value is False (no), when the user log into admin page.
>
> In model.py:
> class RequestForChange (models.Model):
> rfc = models.AutoField (primary_key=True, help_text="This is the grey
> text")
> heading = models.CharField("Heading", max_length=50)
>readiness = models.NullBooleanField("Readiness", blank=True,
> null=True)
>readinessDescription = models.TextField("Description of readiness",
> max_length=250, blank=True, null=True)
>
>
> I found some hints on the web about using get_form from my
> RequestForChangeAdmin page, but it won't work because i get this error
> 'NoneType' object has no attribute 'readiness'
>
>
> Here is what I have in admin.py:
>
> class RequestForChangeAdmin(admin.ModelAdmin):
> formfield_overrides = {
> models.ManyToManyField: {'widget': CheckboxSelectMultiple},
> }
> list_display = ('rfc', 'heading', 'enviroment', 'status')
> search_fields = ('changeId',)
> list_filter = ('enviroment', 'acceptAT', 'status')
> date_hierarchy = 'criticalDate'
> inline = [RequestForChangeInline]
>  def get_form(self, request, obj=None, **kwargs):
> form = super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>  print obj
> if obj.readiness == True:
> self.exclude = ("readinessDescription", )
> form = super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
> return form
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/2c1d74b1-c03c-4c2b-b8db-7d44a06531c4%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 


Timothy Cook
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
MLHIM http://www.mlhim.org

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B%3DOU3WaQAt9LYV8CBuZ8BJaApHCQXoq7twnqDmd1wp7Lkgeew%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Problem hiding fields from admin page based on another fields value

2014-05-30 Thread Hilde Rafaelsen
Hello,

In my django admin page I want to hide some filelds from users if a special 
field value is set. I have tried different solutions to solve my problem 
but is stucked and hope someone can help me,

If you look at my model I want to hide the field readinessDescription if 
readiness value is False (no), when the user log into admin page. 

In model.py:
class RequestForChange (models.Model):
rfc = models.AutoField (primary_key=True, help_text="This is the grey text")
heading = models.CharField("Heading", max_length=50)
   readiness = models.NullBooleanField("Readiness", blank=True, 
null=True)
   readinessDescription = models.TextField("Description of readiness", 
max_length=250, blank=True, null=True) 


I found some hints on the web about using get_form from my 
RequestForChangeAdmin page, but it won't work because i get this error 
'NoneType' object has no attribute 'readiness'


Here is what I have in admin.py:

class RequestForChangeAdmin(admin.ModelAdmin):
formfield_overrides = {
models.ManyToManyField: {'widget': CheckboxSelectMultiple},
}
list_display = ('rfc', 'heading', 'enviroment', 'status')
search_fields = ('changeId',)
list_filter = ('enviroment', 'acceptAT', 'status')
date_hierarchy = 'criticalDate'
inline = [RequestForChangeInline]
 def get_form(self, request, obj=None, **kwargs):
form = super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
 print obj
if obj.readiness == True:
self.exclude = ("readinessDescription", )
form = super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
return form

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2c1d74b1-c03c-4c2b-b8db-7d44a06531c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: hiding fields in admin

2006-07-27 Thread Tamara D. Snyder

Yeah, clearly I followed the wrong tutorial as I was trying to learn  
things.  Ah, well, at least now I *have* learned something.

Thanks for the help, everyone.

Tamara

On Jul 27, 2006, at 9:23 AM, sean wrote:

>
> You should fix those things, editable didn't work because 'False' with
> quotes isn't a valid boolean value. The prepopulate is probably not
> necessary, because all it does is include some javascript that fills
> the field for you as you edit the other fields. Best just to overrride
> the save method and populate the slug field with whatever data you  
> need
> before saving.
>
>
> >


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: hiding fields in admin

2006-07-27 Thread sean

You should fix those things, editable didn't work because 'False' with
quotes isn't a valid boolean value. The prepopulate is probably not
necessary, because all it does is include some javascript that fills
the field for you as you edit the other fields. Best just to overrride
the save method and populate the slug field with whatever data you need
before saving.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: hiding fields in admin

2006-07-27 Thread Tamara D. Snyder

I don't know.  My slug field looks like this:

slug = models.SlugField(
   'Slug',
   prepopulate_from=("title",),
   help_text='Automatically built from the title - do  
not fill in yourself.',
   primary_key='True',
   editable = 'False'
   )

but it definitely shows up in the admin.

Wait!  There it is:  editable='False'  if I make that editable =  
False (without the quotes) then it doesn't show up.  With the quotes  
it does show up, but it is not editable.




On Jul 27, 2006, at 4:08 AM, Sean wrote:

>
> That's weird, because it hides it for me.
> I have a field like this:
> objects_path = models.CharField(maxlength=50, null=True,  
> editable=False)
>
> and it is clearly not visible in the admin.
>
> Tamara D. Snyder wrote:
>> It just makes the field not editable.  Actually, it looks like you
>> can edit the field - type in new stuff, etc. - but when you hit save,
>> that field is not saved.  This is fine with me, because what I
>> *really* wanted was to keep knuckleheads from changing the slug
>> field.  I'd also like to hide it (to make it less tempting to the
>> knuckleheads), so I'll try the javascript thing.  For some reason I
>> was concentrating on just the hiding part and didn't even think of
>> using "editable=false" until you mentioned it.
>>
>>
>
>
> >


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: hiding fields in admin

2006-07-27 Thread Sean

That's weird, because it hides it for me.
I have a field like this:
objects_path = models.CharField(maxlength=50, null=True, editable=False)

and it is clearly not visible in the admin.

Tamara D. Snyder wrote:
> It just makes the field not editable.  Actually, it looks like you  
> can edit the field - type in new stuff, etc. - but when you hit save,  
> that field is not saved.  This is fine with me, because what I  
> *really* wanted was to keep knuckleheads from changing the slug  
> field.  I'd also like to hide it (to make it less tempting to the  
> knuckleheads), so I'll try the javascript thing.  For some reason I  
> was concentrating on just the hiding part and didn't even think of  
> using "editable=false" until you mentioned it.
>
>   


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: hiding fields in admin

2006-07-26 Thread Tamara D. Snyder

It just makes the field not editable.  Actually, it looks like you  
can edit the field - type in new stuff, etc. - but when you hit save,  
that field is not saved.  This is fine with me, because what I  
*really* wanted was to keep knuckleheads from changing the slug  
field.  I'd also like to hide it (to make it less tempting to the  
knuckleheads), so I'll try the javascript thing.  For some reason I  
was concentrating on just the hiding part and didn't even think of  
using "editable=false" until you mentioned it.


On Jul 26, 2006, at 6:58 PM, Sean wrote:

>
> Tamara D. Snyder wrote:
>> Thank you, this works pretty well.
>>
>> Actually, "editable=false" does not hide the field from the admin
>>
> But what else does it do?
>
>
> >


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: hiding fields in admin

2006-07-26 Thread Sean

Tamara D. Snyder wrote:
> Thank you, this works pretty well.
>
> Actually, "editable=false" does not hide the field from the admin
>   
But what else does it do?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: hiding fields in admin

2006-07-26 Thread Tamara D. Snyder

Thank you, this works pretty well.

Actually, "editable=false" does not hide the field from the admin,  
but it will keep the field from being edited, and I can use the  
javascript trick to make it hidden, so all is well for me.

Thanks a lot, guys!

On Jul 26, 2006, at 4:02 PM, Sean wrote:

>
> Maybe you would want the "editable=False" parameter in your model,  
> which
> hides the field from the admin. Then simply populate the field in the
> save method.
>
> Tamara D. Snyder wrote:
>> Hi all,
>>
>> In my "Event" model I have a slug field that is automatically
>> generated from another field.  I would like to hide the slug field
>> from admin users, but still allow it to be automatically generated.
>> I know I can hide it by using the "fields" parameter in the admin
>> class of my model.  But if I do this then the slug field is not
>> automatically generated when I create a new event.  Is there a way to
>> hide the slug field, but still have it be filled in when I create a
>> new event?
>>
>> Thanks!
>>
>> Tamara
>>
>>>
>>
>>
>
>
> >


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: hiding fields in admin

2006-07-26 Thread Aidas Bendoraitis

One more way would be to have a javascript function which changes
 to  for the slug field.
Something like this:

window.onload = function() {
document.getElementById("id_slug").type="hidden";
}

Good luck!
Aidas Bendoraitis [aka Archatas]


On 7/27/06, Sean <[EMAIL PROTECTED]> wrote:
>
> Maybe you would want the "editable=False" parameter in your model, which
> hides the field from the admin. Then simply populate the field in the
> save method.
>
> Tamara D. Snyder wrote:
> > Hi all,
> >
> > In my "Event" model I have a slug field that is automatically
> > generated from another field.  I would like to hide the slug field
> > from admin users, but still allow it to be automatically generated.
> > I know I can hide it by using the "fields" parameter in the admin
> > class of my model.  But if I do this then the slug field is not
> > automatically generated when I create a new event.  Is there a way to
> > hide the slug field, but still have it be filled in when I create a
> > new event?
> >
> > Thanks!
> >
> > Tamara
> >
> > >
> >
> >
>
>
> >
>

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: hiding fields in admin

2006-07-26 Thread Sean

Maybe you would want the "editable=False" parameter in your model, which
hides the field from the admin. Then simply populate the field in the
save method.

Tamara D. Snyder wrote:
> Hi all,
>
> In my "Event" model I have a slug field that is automatically  
> generated from another field.  I would like to hide the slug field  
> from admin users, but still allow it to be automatically generated.   
> I know I can hide it by using the "fields" parameter in the admin  
> class of my model.  But if I do this then the slug field is not  
> automatically generated when I create a new event.  Is there a way to  
> hide the slug field, but still have it be filled in when I create a  
> new event?
>
> Thanks!
>
> Tamara
>
> >
>
>   


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: hiding fields in admin

2006-07-26 Thread Julio Nobrega

  You can override the save() method and generate the slug yourself.
There's also a templatetag that 'slugfies' a string. I think you can
either use it to output the var or import the function on your save().


On 7/26/06, Tamara D. Snyder <[EMAIL PROTECTED]> wrote:
>
> Hi all,
>
> In my "Event" model I have a slug field that is automatically
> generated from another field.  I would like to hide the slug field
> from admin users, but still allow it to be automatically generated.
> I know I can hide it by using the "fields" parameter in the admin
> class of my model.  But if I do this then the slug field is not
> automatically generated when I create a new event.  Is there a way to
> hide the slug field, but still have it be filled in when I create a
> new event?
>
> Thanks!
>
> Tamara

-- 
Julio Nobrega - http://www.inerciasensorial.com.br

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



hiding fields in admin

2006-07-26 Thread Tamara D. Snyder

Hi all,

In my "Event" model I have a slug field that is automatically  
generated from another field.  I would like to hide the slug field  
from admin users, but still allow it to be automatically generated.   
I know I can hide it by using the "fields" parameter in the admin  
class of my model.  But if I do this then the slug field is not  
automatically generated when I create a new event.  Is there a way to  
hide the slug field, but still have it be filled in when I create a  
new event?

Thanks!

Tamara

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Hiding fields in admin interface

2005-11-27 Thread pgross

Thanks, that's really helpful.  I missed that argument when I was going
through the docs.



Re: Hiding fields in admin interface

2005-11-27 Thread oggie rob

> The core of my problem is that the foreign key
field points to a table that is huge (tens of thousands of values).

Ahh, that makes it much easier! You can put the foreign key in there
with the field argument "raw_id_admin=True". It will be much quicker to
load and much cleaner to use.

class Poll(meta.Model):
 huge = meta.ForeignKey(Huge, raw_id_admin=True)

 -rob



Re: Hiding fields in admin interface

2005-11-27 Thread pgross

I get the same problem with this field.  It doesn't show up in the
admin interface, but when I try to save the object, it blanks the field
and tries to update it in the database.  Since the field I want hidden
is a foreign key, the update statement dies saying "ERROR: invalid
input syntax for integer."

I can get around this by adding a _pre_save() method, looking up the
old value, and the setting it on the new object.  However, this is
pretty messy.

Is there a way to get the field to display on the admin as merely
uneditable text, then?  The core of my problem is that the foreign key
field points to a table that is huge (tens of thousands of values).
When the admin page loads, it makes a drop down box with all of these
values.  Therefore, the admin page size is really large and it takes a
long time to load.  I would rather just show the text of the field or
hide it altogether, without showing a drop down of all the possible
values.



Re: Hiding fields in admin interface

2005-11-26 Thread oggie rob

Did you try the "editable=False" argument, as in:
class MyModel(meta.Model):
   myField = meta.CharField(maxlength=20, editable=False)



Hiding fields in admin interface

2005-11-26 Thread pgross

Is it possible to hide fields in the admin interface?  I want my admin
interface to be able to modify only some fields on an already created
object.  I want the fields that aren't displayed to merely stay the
same.  However, if I leave the undesired fields out of the fields list,
I get errors when I try to save.  I think it blanks those fields out
rather than just leaving them how they were.