How to override Model.__init__ without breaking `using(db)`?

2022-10-29 Thread Robert Leach
Hi,

I have a Model superclass called `MaintainedModel` that other models 
inherit from.  It itself inherits from django.db.models.Model and overrides 
its __init__ method in order to implement some controls on fields using 
decorators in the derived models.  It all works very well in the realm of 
the default database... BUT I realized yesterday that it breaks operations 
on our validation database.  I describe it in some detail on this stack post 
<https://stackoverflow.com/questions/74241257/how-to-override-model-init-and-respect-usingdb-in-django/74241582#74241582>,
 
but to summarize my hunch, the override of init is breaking the 
`.using(db)` statement in this call:

```
FCirc.objects.using(self.db).get_or_create(
serum_sample=sample,
tracer=tracer,
element=label.element,
)
```

As a proof of concept, I fix that broken association in my "answer" on the 
stack post by axplicitly setting a `_state` attribute on the FCirc object 
before calling `get_or_create` and that fix works.

So my question for you all is: how do I preserve the functionality of 
`.using(db)` in my MaintainedModel superclass?

Thanks,
Rob

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5767c6e1-7636-462d-a8cc-5f819350f755n%40googlegroups.com.


Re: User model override and authentication

2022-10-24 Thread Abhishek Kumar
If I may ask: why do you want to do this? If you just want to change what's
displayed on Django Admin for example, you can do that without messing up
with the code.

On Tue, Oct 25, 2022 at 2:48 AM Ayser shuhaib 
wrote:

> Oi Rafael
>
> I’m sure this tutorial will help you:
>
> https://youtu.be/GdfLXHhNABE
>
> On Mon, 24 Oct 2022 at 23:14, Rafael Noronha 
> wrote:
>
>> Hello guys,
>> I'm not advanced in Django and would like to know how and if it's
>> possible to do it.
>>
>> I need to override Django's user model, and change the fields "username"
>> to "sr_usuario" and "password" to "sr_password", but I would like to
>> continue using all Django's default authentication scheme and permissions.
>> I want not only to change the description in the database or a label, I
>> want to change the name of the field in the model, for when for example I
>> needed to make a query, I would use
>> User.objects.filter(sr_usuario="user_name") and everything would work
>> usually.
>>
>> It's possible? I couldn't find anything in the documentation or on forums
>> I've searched.
>>
>> Thank you very much in advance!
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/101d09bb-b076-4e54-9cbc-776ff93c979fn%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/101d09bb-b076-4e54-9cbc-776ff93c979fn%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAE0AZGKackLiX%2B83RPyNfHr9gLFX%3DYwrdrKM40tcwBPR48zjWQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAE0AZGKackLiX%2B83RPyNfHr9gLFX%3DYwrdrKM40tcwBPR48zjWQ%40mail.gmail.com?utm_medium=email_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAORpQohaf_bYGA3VjjbmFCj%2BAC9hpt6aqhgwiHHRVLmFxm01oQ%40mail.gmail.com.


Re: User model override and authentication

2022-10-24 Thread Muhammad Juwaini Abdul Rahman
I never tried this, but maybe you can.

Inherit the User model, then add two new lines:

class DerivedUser(User):
.
sr_usuario = username
sr_password = password

On Tue, 25 Oct 2022 at 05:14, Rafael Noronha 
wrote:

> Hello guys,
> I'm not advanced in Django and would like to know how and if it's possible
> to do it.
>
> I need to override Django's user model, and change the fields "username"
> to "sr_usuario" and "password" to "sr_password", but I would like to
> continue using all Django's default authentication scheme and permissions.
> I want not only to change the description in the database or a label, I
> want to change the name of the field in the model, for when for example I
> needed to make a query, I would use
> User.objects.filter(sr_usuario="user_name") and everything would work
> usually.
>
> It's possible? I couldn't find anything in the documentation or on forums
> I've searched.
>
> Thank you very much in advance!
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/101d09bb-b076-4e54-9cbc-776ff93c979fn%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/101d09bb-b076-4e54-9cbc-776ff93c979fn%40googlegroups.com?utm_medium=email_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFKhtoSA87sYcO8_0X%2BpW1Qj%3DOjBu43N08KcpPe7AtHkG19sNQ%40mail.gmail.com.


Re: User model override and authentication

2022-10-24 Thread Ayser shuhaib
Oi Rafael

I’m sure this tutorial will help you:

https://youtu.be/GdfLXHhNABE

On Mon, 24 Oct 2022 at 23:14, Rafael Noronha 
wrote:

> Hello guys,
> I'm not advanced in Django and would like to know how and if it's possible
> to do it.
>
> I need to override Django's user model, and change the fields "username"
> to "sr_usuario" and "password" to "sr_password", but I would like to
> continue using all Django's default authentication scheme and permissions.
> I want not only to change the description in the database or a label, I
> want to change the name of the field in the model, for when for example I
> needed to make a query, I would use
> User.objects.filter(sr_usuario="user_name") and everything would work
> usually.
>
> It's possible? I couldn't find anything in the documentation or on forums
> I've searched.
>
> Thank you very much in advance!
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/101d09bb-b076-4e54-9cbc-776ff93c979fn%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/101d09bb-b076-4e54-9cbc-776ff93c979fn%40googlegroups.com?utm_medium=email_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAE0AZGKackLiX%2B83RPyNfHr9gLFX%3DYwrdrKM40tcwBPR48zjWQ%40mail.gmail.com.


User model override and authentication

2022-10-24 Thread Rafael Noronha
Hello guys,
I'm not advanced in Django and would like to know how and if it's possible 
to do it.

I need to override Django's user model, and change the fields "username" to 
"sr_usuario" and "password" to "sr_password", but I would like to continue 
using all Django's default authentication scheme and permissions. I want 
not only to change the description in the database or a label, I want to 
change the name of the field in the model, for when for example I needed to 
make a query, I would use User.objects.filter(sr_usuario="user_name") and 
everything would work usually.

It's possible? I couldn't find anything in the documentation or on forums 
I've searched.

Thank you very much in advance!

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/101d09bb-b076-4e54-9cbc-776ff93c979fn%40googlegroups.com.


Re: ModelMultipleChoiceField - override validation

2021-11-22 Thread Earl Lapus
I was able to resolve this by overriding `clean()` instead of 
`to_python()`. In there, I've the set correct queryset to use for 
validation.

I still could not explain why `to_python()` is not called.

On Saturday, November 20, 2021 at 8:38:47 AM UTC+8 Earl Lapus wrote:

> Hi,
>
> I have a ModelForm that has a ModelMultipleChoiceField. In the said field, 
> I've set the queryset to none and assigned the FilteredSelectMultiple as 
> the widget for the field.
>
> It looks like this:
>
> class MyForm(forms.ModelForm):
> myfield = ModelMultipleChoiceField(
> queryset=SomeModel.objects.none(),
> widget=admin.widgets.FilteredSelectMultiple('SomeModel', False),
> required=False
> )
>
> I added some javascript on the template to dynamically add items to the 
> widget based on a value from another field. That part already works. But, I 
> am running into an error during submit - validation error. An example error 
> I get is: *"Select a valid choice. 4 is not one of the available 
> choices."  *This is expected since I've set the queryset to be empty, so 
> values will match during validation.
>
> Where should I override the validation? I tried creating a 
> ModelMultipleChoiceField child class and implemented the `to_python()` 
> method but it seems like that method is not called. Is there any 
> documentation that can help me arrive at an answer for this?
>
> Cheers,
> Earl
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fbe2b159-7d3c-4c62-946c-4f662e4cff7en%40googlegroups.com.


ModelMultipleChoiceField - override validation

2021-11-19 Thread Earl Lapus
Hi,

I have a ModelForm that has a ModelMultipleChoiceField. In the said field, 
I've set the queryset to none and assigned the FilteredSelectMultiple as 
the widget for the field.

It looks like this:

class MyForm(forms.ModelForm):
myfield = ModelMultipleChoiceField(
queryset=SomeModel.objects.none(),
widget=admin.widgets.FilteredSelectMultiple('SomeModel', False),
required=False
)

I added some javascript on the template to dynamically add items to the 
widget based on a value from another field. That part already works. But, I 
am running into an error during submit - validation error. An example error 
I get is: *"Select a valid choice. 4 is not one of the available choices."  
*This is expected since I've set the queryset to be empty, so values will 
match during validation.

Where should I override the validation? I tried creating a 
ModelMultipleChoiceField child class and implemented the `to_python()` 
method but it seems like that method is not called. Is there any 
documentation that can help me arrive at an answer for this?

Cheers,
Earl

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5db88977-df0c-4fd1-a10e-feb60b610273n%40googlegroups.com.


Re: override save() twice in django model!

2021-05-01 Thread RITIK SONI
yea! ig you are right! we cant override it twice.

On Sat, May 1, 2021 at 7:25 PM Kunal Solanke 
wrote:

> I don't think so, why not do in one function or you can use pre save and
> pist save signals
>
> On Sat, May 1, 2021, 19:11 RITIK SONI  wrote:
>
>> am i able to override save() method of a django model twice?
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/b56f7397-66c1-44e5-8502-a83717861d54n%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/b56f7397-66c1-44e5-8502-a83717861d54n%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAOecAnxvL%2BVK_ExV5rWa_mYH9Swp8NBNMu8EYQrT8%3Dy%3DhzCqdA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAOecAnxvL%2BVK_ExV5rWa_mYH9Swp8NBNMu8EYQrT8%3Dy%3DhzCqdA%40mail.gmail.com?utm_medium=email_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADe46ZEFmJ_su2bmVFVZcbQqTVjLL2Zyf%2B-2KiZAVq8j1EhWVg%40mail.gmail.com.


Re: override save() twice in django model!

2021-05-01 Thread Kunal Solanke
I don't think so, why not do in one function or you can use pre save and
pist save signals

On Sat, May 1, 2021, 19:11 RITIK SONI  wrote:

> am i able to override save() method of a django model twice?
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/b56f7397-66c1-44e5-8502-a83717861d54n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/b56f7397-66c1-44e5-8502-a83717861d54n%40googlegroups.com?utm_medium=email_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOecAnxvL%2BVK_ExV5rWa_mYH9Swp8NBNMu8EYQrT8%3Dy%3DhzCqdA%40mail.gmail.com.


override save() twice in django model!

2021-05-01 Thread RITIK SONI
am i able to override save() method of a django model twice?

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b56f7397-66c1-44e5-8502-a83717861d54n%40googlegroups.com.


Form will not submit after __init__ override

2020-09-10 Thread Kuyateh Yankz
I got a user-based dropdown working but now the form does not submit. here 
are my files  

MODEL.PY name= models.ForeignKey(User, on_delete=models.CASCADE, null=True, 
blank=True) FORMS.PY class MyForm(forms.ModelForm): class Meta: model = 
MyModel fields = ('name', ) def __init__(self, user, *args, **kwargs): 
self.user = user super(MyForm, self).__init__(*args, **kwargs) 
self.fields['name'].queryset = OtherModel.objects.filter(user=self.user) 
VIEWS.PY class MyView(CreateView): model = MyModel form_class = MyFrom 
template_name = 'users/form.html' success_url = reverse_lazy('index') def 
get_form_kwargs(self): kwargs = {'user' : self.request.user , } return 
kwargs

{% extends 'users/backend.html' %} {% load static %} {% block main %}  {% csrf_token %} {{ form }} Submit  {% endblock %}  

NOTE: Without the def get_form_kwargs(self): in the views, the form filter 
grabs everything but with it does not submit. Any help will be appreciated 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/195b7d70-0afe-4079-979c-eb38061102den%40googlegroups.com.


how to override options of choices in django model form

2020-07-28 Thread Sujata Aghor
Hello All,

How can I override options of choices in django model form from the model
field ?
Below is my code -

*models.py:*

class XXX(models.Model):
StatusType = models.TextChoices('StatusType', const.status_values)
status = models.CharField(max_length=100, default='abc',
choices=StatusType.choices,)


*views.py:*

class XXXUpdateView(LoginRequiredMixin, UserPassesTestMixin, UpdateView):
model = XXX
fields = ['aaa', 'bbb', 'status']

def get_form(self):
form = super().get_form()
form.title = self.kwargs['title']
   # NOW HERE I WANT TO RESET THE VALUE OF STATUS DROPDOWN BASED ON
CERTAIN CONDITION.
return form
-- 

Can anyone suggest something
Thanks in advance !

Thanks & Regards!
Sujata S. Aghor

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJCP8KB06LxS8m8iNfpe0h30Sa%3Dro2N1AuyGM4sQXreW4f-Pig%40mail.gmail.com.


How to do an override of fields based on it's value in an aggregation query (join on multiple columns)

2020-02-03 Thread Vladimir K.
Hi 

My case is fully depicted here: 
https://stackoverflow.com/questions/59991771/django-how-to-do-an-override-of-fields-based-on-its-value-in-an-aggregation-qu
 
Any ideas? The next step would be to do a RawSQL but I think that it should 
be possible with the ORM.

Best regards and thanks in advance
Vladimir
 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b308fc0a-6234-434e-9116-62f1eb7ed959%40googlegroups.com.


Re: Override value of a TextField class method.

2020-01-07 Thread Fabio da Silva Pedro
OK, thank's for this!

Em ter., 7 de jan. de 2020 às 03:03, Mohamed A  escreveu:

> Hint:.. __init__ is a constructor not any method.
>
> Le lun. 6 jan. 2020 à 23:02, Fabio da Silva Pedro <
> fabio.silvape...@gmail.com> a écrit :
>
>> Easy. You need to provide attrs as dict to the new object.
>>>
>>>
>> Ok, I thought about that too, but I don't know how to do it, I copied the
>> whole method and pasted it into my model and tried to access its
>> superclass, but I didn't get it!
>> Maybe I'm doing something wrong yet.
>>
>> Would you have any examples for me?
>>
>> I can easily do this with jQuery, but I want to learn how to do this
>> using just Django and for that I still have little experience in method
>> override.
>>
>> best regards!
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAGE5jT83u5wahCwwzfF2b0td_MzEgj9L-DV4e9DZH8mcWq7G0Q%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAGE5jT83u5wahCwwzfF2b0td_MzEgj9L-DV4e9DZH8mcWq7G0Q%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAJenkLCaqXO15urag46XLKzpOoNwbzOay5H1n-Pn3NovhssL%3DA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAJenkLCaqXO15urag46XLKzpOoNwbzOay5H1n-Pn3NovhssL%3DA%40mail.gmail.com?utm_medium=email_source=footer>
> .
>


-- 
*Fábio S. Pedro*
(21) 97569-7573(WhatsApp).

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGE5jT9rB5K%2BZF8mSeU%3DeWdOd%3D6SUdde3BZqO%3Drct4h2jAL5jw%40mail.gmail.com.


Re: Override value of a TextField class method.

2020-01-06 Thread Mohamed A
Hint:.. __init__ is a constructor not any method.

Le lun. 6 jan. 2020 à 23:02, Fabio da Silva Pedro <
fabio.silvape...@gmail.com> a écrit :

> Easy. You need to provide attrs as dict to the new object.
>>
>>
> Ok, I thought about that too, but I don't know how to do it, I copied the
> whole method and pasted it into my model and tried to access its
> superclass, but I didn't get it!
> Maybe I'm doing something wrong yet.
>
> Would you have any examples for me?
>
> I can easily do this with jQuery, but I want to learn how to do this using
> just Django and for that I still have little experience in method override.
>
> best regards!
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAGE5jT83u5wahCwwzfF2b0td_MzEgj9L-DV4e9DZH8mcWq7G0Q%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAGE5jT83u5wahCwwzfF2b0td_MzEgj9L-DV4e9DZH8mcWq7G0Q%40mail.gmail.com?utm_medium=email_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJenkLCaqXO15urag46XLKzpOoNwbzOay5H1n-Pn3NovhssL%3DA%40mail.gmail.com.


Re: Override value of a TextField class method.

2020-01-06 Thread Fabio da Silva Pedro
>
> Easy. You need to provide attrs as dict to the new object.
>
>
Ok, I thought about that too, but I don't know how to do it, I copied the
whole method and pasted it into my model and tried to access its
superclass, but I didn't get it!
Maybe I'm doing something wrong yet.

Would you have any examples for me?

I can easily do this with jQuery, but I want to learn how to do this using
just Django and for that I still have little experience in method override.

best regards!

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGE5jT83u5wahCwwzfF2b0td_MzEgj9L-DV4e9DZH8mcWq7G0Q%40mail.gmail.com.


Re: Override value of a TextField class method.

2020-01-06 Thread Mohamed A
Easy. You need to provide attrs as dict to the new object.

Le lun. 6 jan. 2020 à 21:36, Fabio da Silva Pedro <
fabio.silvape...@gmail.com> a écrit :

> Hi everyone!
>
> this is an excerpt line from my model
>
> observacoes = models.TextField(null=True, blank=True, 
> verbose_name='Informações complementares')
>
>
> How i do override a field type *TextField* and change your internal *class
> value Textarea*, this is a widget from TextField Class and override this
> method below:
>
> def __init__(self, attrs=None):
> # Use slightly better defaults than HTML's 20x2 box
> default_attrs = {'cols': '40', 'rows': '10'}
> if attrs:
> default_attrs.update(attrs)
> super().__init__(default_attrs)
>
>
> I need change value from *default_attrs = {'rows':'10'}* for
> *{'rows':'4'} *
>
>  How can I override this in my model or in my view?
>
> Thanks for watching!
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/adef9112-df5b-4b03-9861-97d1495dd00b%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/adef9112-df5b-4b03-9861-97d1495dd00b%40googlegroups.com?utm_medium=email_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJenkLDF5My0GH3mFdCPftEq%3DeH0Mep4O83jPK4OY0Tj8Jk5LQ%40mail.gmail.com.


Override value of a TextField class method.

2020-01-06 Thread Fabio da Silva Pedro
Hi everyone!

this is an excerpt line from my model

observacoes = models.TextField(null=True, blank=True, verbose_name='Informações 
complementares')


How i do override a field type *TextField* and change your internal *class 
value Textarea*, this is a widget from TextField Class and override this 
method below:

def __init__(self, attrs=None):
# Use slightly better defaults than HTML's 20x2 box
default_attrs = {'cols': '40', 'rows': '10'}
if attrs:
default_attrs.update(attrs)
super().__init__(default_attrs)


I need change value from *default_attrs = {'rows':'10'}* for *{'rows':'4'} *

 How can I override this in my model or in my view?

Thanks for watching!

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/adef9112-df5b-4b03-9861-97d1495dd00b%40googlegroups.com.


Django does not Override Settings in Template Tag Testing

2019-12-11 Thread Eray Erdin
I have actually provided quite much verbose information in Stackoverflow 
<https://stackoverflow.com/questions/59251954/django-does-not-override-settings-in-template-tag-testing>.
 
I have a problem overriding settings as testing template tags. I leave this 
here in case you are interested.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8fa4ce5c-cdd1-4c1c-a00d-97554cf86633%40googlegroups.com.


Re: Why and when I should override the default AdminSite

2019-10-12 Thread Derek
Not sure what you mean by "overwrite" - there are lots of ways to extend or 
customise Django admin, not the least of which is retheming it e.g.  Django 
Suite or Grappelli. 

On Wednesday, 9 October 2019 10:11:27 UTC+2, Jérôme Le Carrou wrote:
>
> I am newbie in DJango
> I've started to read Django documentation and particularly the admin 
> related documentation
>
> I would like to understand when an why it should be pertinent to override 
> the default AdminSite
>
> regards
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c3e02395-029c-4ae6-be3b-e121f877b8d4%40googlegroups.com.


Re: Why and when I should override the default AdminSite

2019-10-12 Thread Derek
Hi

I have also been working with Django for many, many years.  All of our apps 
have been based around the many features/options already built-in to the 
admin and it works perfectly "as is".  There is really a lot you can do 
with it if your users are accustomed to working with more traditional 
grid-like database apps (and/or spreadsheets). For reporting you need to 
write your own code but its easy to add this in.  Adding "logic" to do data 
checks and make more complex changes is possible via actions.  The main 
advantage of the admin is that you're not writing a whole lot of code that 
you then have to support!

If your users want a more "modern" front-end e.g. a Single Page App, then 
yes, you will use Django simply for its ORM-modelling, add the Django Rest 
Framework on top, and then develop your front-end using whatever JS 
framework seems most popular these days.

My 2c
Derek

On Wednesday, 9 October 2019 19:32:17 UTC+2, Jani Tiainen wrote:
>
> Hi.
>
> I've been working with Django about 10 years and yet I haven't need for 
> overriding admin.
>
> Admin is great tool for CRUD while developing but I wouldn't push it too 
> far. Specially trying to put any business logic in admin doesn't go well in 
> the long run. 
>
> And it's really easy to build proper management console with generic class 
> based views which can cope with business requirements easily.
>
> ke 9. lokak. 2019 klo 11.12 Jérôme Le Carrou  > kirjoitti:
>
>> I am newbie in DJango
>> I've started to read Django documentation and particularly the admin 
>> related documentation
>>
>> I would like to understand when an why it should be pertinent to override 
>> the default AdminSite
>>
>> regards
>>
>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/9ecd5e6a-c1b4-4642-8cda-f5746b4b9216%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/9ecd5e6a-c1b4-4642-8cda-f5746b4b9216%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/598a5ce8-4f11-4921-b669-9ba13727095e%40googlegroups.com.


Re: Why and when I should override the default AdminSite

2019-10-09 Thread Jani Tiainen
Hi.

I've been working with Django about 10 years and yet I haven't need for
overriding admin.

Admin is great tool for CRUD while developing but I wouldn't push it too
far. Specially trying to put any business logic in admin doesn't go well in
the long run.

And it's really easy to build proper management console with generic class
based views which can cope with business requirements easily.

ke 9. lokak. 2019 klo 11.12 Jérôme Le Carrou 
kirjoitti:

> I am newbie in DJango
> I've started to read Django documentation and particularly the admin
> related documentation
>
> I would like to understand when an why it should be pertinent to override
> the default AdminSite
>
> regards
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/9ecd5e6a-c1b4-4642-8cda-f5746b4b9216%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/9ecd5e6a-c1b4-4642-8cda-f5746b4b9216%40googlegroups.com?utm_medium=email_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHn91ocBFuY%2BFuW5mSO1RfhbT%2BvCbkFVmTRvF0tO93ZQeK23kQ%40mail.gmail.com.


Re: Why and when I should override the default AdminSite

2019-10-09 Thread Mike Dewhirst
That's easy. When the Admin site doesn't do exactly what you want. So press on 
and use it. You'll know precisely when you need to tweak something and that's 
when to dig out the docs again  :-) 

Connected by Motorola

Jérôme Le Carrou  wrote:

>I am newbie in DJango
>
>I've started to read Django documentation and particularly the admin related 
>documentation
>
>
>I would like to understand when an why it should be pertinent to override the 
>default AdminSite
>
>
>regards
>
>-- 
>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 view this discussion on the web visit 
>https://groups.google.com/d/msgid/django-users/9ecd5e6a-c1b4-4642-8cda-f5746b4b9216%40googlegroups.com.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/gund0nqsblltuq2ls4jqex8w.1570624690996%40email.android.com.


Why and when I should override the default AdminSite

2019-10-09 Thread Jérôme Le Carrou
I am newbie in DJango
I've started to read Django documentation and particularly the admin 
related documentation

I would like to understand when an why it should be pertinent to override 
the default AdminSite

regards

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9ecd5e6a-c1b4-4642-8cda-f5746b4b9216%40googlegroups.com.


Re: How do I override default date formats per locale in Django?

2019-07-25 Thread אורי
*Update:* I found out that it's possible to override formats per locale in this
link <https://docs.djangoproject.com/en/1.11/topics/i18n/formatting/>, and
added formats for en and he locales, but they don't work. I added a
debugging code which you can see here
<https://github.com/speedy-net/speedy-net/blob/uri_main_branch_2019-07-26_c/speedy/core/locale/en/formats.py#L4>,
but it doesn't work. It shows dates like Jan. 1, 2018 and not as I expect.

I also don't know if DATE_FORMAT should be preceded by settings. in the
template, but it doesn't show anything without it.
אורי
u...@speedy.net


‪On Wed, Jul 24, 2019 at 8:45 PM ‫אורי‬‎  wrote:‬

> Hi,
>
> We are using Django 1.11 for Speedy Net. I want to override the default
> values of DATE_FORMAT and MONTH_DAY_FORMAT in English, but keep the default
> values (or define them again) in Hebrew. So they will not be the same and
> will not be identical to Django's default values. In English we will have:
>
> DATE_FORMAT = 'j F Y'
> MONTH_DAY_FORMAT = 'j F'
> YEAR_FORMAT = 'Y'
>
> And in Hebrew:
>
> DATE_FORMAT = 'j בF Y'
> MONTH_DAY_FORMAT = 'j בF'
>
> (and YEAR_FORMAT will be the same).
>
> The template currently looks like this:
>
> {% if can_view_profile and user.date_of_birth %}
> {% if can_view_dob_day_month or can_view_dob_year %}
> 
> {% if can_view_dob_day_month %}{% trans 'Birth Date' %}{%
> elif can_view_dob_year %}{% trans 'Birth Year' %}{% endif %}
> 
> {% if can_view_dob_day_month and can_view_dob_year %}
> {{ user.date_of_birth|date:settings.DATE_FORMAT }}
> {% elif can_view_dob_day_month %}
> {{ user.date_of_birth|date:settings.MONTH_DAY_FORMAT }}
> {% elif can_view_dob_year %}
> {{ user.date_of_birth|date:settings.YEAR_FORMAT }}
> {% endif %}
> 
> 
> {% endif %}
> {% endif %}
>
> And I want it to display the dates in these formats in each language. How
> do I do it?
> אורי
> u...@speedy.net
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABD5YeFaVPNC1RT3QqTPv7oVyPjSCtZZq_aO7UcHgMr%3DYTm16w%40mail.gmail.com.


How do I override default date formats per locale in Django?

2019-07-24 Thread אורי
Hi,

We are using Django 1.11 for Speedy Net. I want to override the default
values of DATE_FORMAT and MONTH_DAY_FORMAT in English, but keep the default
values (or define them again) in Hebrew. So they will not be the same and
will not be identical to Django's default values. In English we will have:

DATE_FORMAT = 'j F Y'
MONTH_DAY_FORMAT = 'j F'
YEAR_FORMAT = 'Y'

And in Hebrew:

DATE_FORMAT = 'j בF Y'
MONTH_DAY_FORMAT = 'j בF'

(and YEAR_FORMAT will be the same).

The template currently looks like this:

{% if can_view_profile and user.date_of_birth %}
{% if can_view_dob_day_month or can_view_dob_year %}

{% if can_view_dob_day_month %}{% trans 'Birth Date' %}{%
elif can_view_dob_year %}{% trans 'Birth Year' %}{% endif %}

{% if can_view_dob_day_month and can_view_dob_year %}
{{ user.date_of_birth|date:settings.DATE_FORMAT }}
{% elif can_view_dob_day_month %}
{{ user.date_of_birth|date:settings.MONTH_DAY_FORMAT }}
{% elif can_view_dob_year %}
{{ user.date_of_birth|date:settings.YEAR_FORMAT }}
{% endif %}


{% endif %}
{% endif %}

And I want it to display the dates in these formats in each language. How
do I do it?
אורי
u...@speedy.net

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABD5YeHdi%2BARNmvc7fUyV8hKkySgmxXs19mQzoh2PU_xRwYoEA%40mail.gmail.com.


Re: Can I override __new__ in Django ModelForm?

2019-07-10 Thread Jani Tiainen
Hi.

You can add fields dynamically on model __init__ method and AFAIK that's
best and recommended way to do it.

I'm not sure is that even in Django docs.


ke 10. heinäk. 2019 klo 17.44 אורי  kirjoitti:

> Hi,
>
> I have a ModelForm with Django 1.11, and I'm moving a few fields to
> another model. Calling make_migrations causes an error because these fields
> don't exist in the current model. I added some of the fields to the form,
> but one of the fields is a TranslatedField and therefore there are
> currently 2 fields, and in the future there might be more, depending on the
> number of languages. The name of the field is city, and currently I get an
> error message "Unknown field(s) (city_en, city_he) specified for
> SiteProfile" (because I'm using 2 languages - "en" and "he") - but I want
> to create all the fields dynamically with a for loop over the languages we
> use in the project. Can I override (and is it a good programming method)
> the __new__ method or is there another way? I prefer not to hard-code the
> specific field names (city_en and city_he) because they may change in the
> future, depending on how many languages we use.
>
> You can see my current commit (not working) on GitHub:
>
> https://github.com/speedy-net/speedy-net/commit/f2c9b306c1a5f7a41b19d605f7871c07a67af93f
>
>
> And the current code of this branch:
>
> https://github.com/speedy-net/speedy-net/blob/uri_move_fields_to_speedy_net_2019-07-10_b/speedy/match/accounts/forms.py
>
>
> I would like to know what is the best programming method to define a
> dynamic list of fields (which are all identical, and only one of them will
> be used, the other are removed in the __init__ method) in a ModelForm where
> the fields are saved in another model (there are 2 models but only one
> form).
>
> I still didn't commit the migrations because of this error when running
> make_migrations.
>
> (I defined a command make_migrations which only does makemigrations)
>
> Thanks!
> אורי
> u...@speedy.net
>
> --
> 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/CABD5YeFv7HFCmFqvQeg5HdQLBs%3DYbxbRO4oukpdFX175exNSHA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CABD5YeFv7HFCmFqvQeg5HdQLBs%3DYbxbRO4oukpdFX175exNSHA%40mail.gmail.com?utm_medium=email_source=footer>
> .
> 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/CAHn91odauAH%2B2Jnjdb7Yx61juKqmo3h2M05B3uNc1NDig7D9UA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Can I override __new__ in Django ModelForm?

2019-07-10 Thread אורי
Hi,

I have a ModelForm with Django 1.11, and I'm moving a few fields to another
model. Calling make_migrations causes an error because these fields don't
exist in the current model. I added some of the fields to the form, but one
of the fields is a TranslatedField and therefore there are currently 2
fields, and in the future there might be more, depending on the number of
languages. The name of the field is city, and currently I get an error
message "Unknown field(s) (city_en, city_he) specified for SiteProfile"
(because I'm using 2 languages - "en" and "he") - but I want to create all
the fields dynamically with a for loop over the languages we use in the
project. Can I override (and is it a good programming method) the __new__
method or is there another way? I prefer not to hard-code the specific
field names (city_en and city_he) because they may change in the future,
depending on how many languages we use.

You can see my current commit (not working) on GitHub:
https://github.com/speedy-net/speedy-net/commit/f2c9b306c1a5f7a41b19d605f7871c07a67af93f


And the current code of this branch:
https://github.com/speedy-net/speedy-net/blob/uri_move_fields_to_speedy_net_2019-07-10_b/speedy/match/accounts/forms.py


I would like to know what is the best programming method to define a
dynamic list of fields (which are all identical, and only one of them will
be used, the other are removed in the __init__ method) in a ModelForm where
the fields are saved in another model (there are 2 models but only one
form).

I still didn't commit the migrations because of this error when running
make_migrations.

(I defined a command make_migrations which only does makemigrations)

Thanks!
אורי
u...@speedy.net

-- 
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/CABD5YeFv7HFCmFqvQeg5HdQLBs%3DYbxbRO4oukpdFX175exNSHA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to override default Django Admin Panel Model display to Customization

2019-04-17 Thread Derek
Proxy models, with an associated Manager, are one way to achieve this - 
assuming your criteria are fixed.

On Monday, 15 April 2019 15:25:49 UTC+2, Balaji Shetty wrote:
>
> Hi 
>
> When i do login using Django Admin Panel , i can easily perform CRUD 
> operation on Models.
>
> can i customize the display of Models Records in django Admin Panel 
> Itself, when I select the model, I get all the records, But i want to 
> filter the records based on some Criteria.
>
> Here is my model . Code executes.
>
>
>
> class EmployeeManager(models.Manager):
> def get_queryset(self):
> return super(EmployeeManager, 
> self).get_queryset().filter(gender='F')
>
>
>
>
>
> class Employee(models.Model):
>   gender_choices = (
>("M", "Male"),
>("F", "Female")
>   )
>   roles_choices = (
>("J", "Junior"),
>("S", "Senior"),
>   )
>   first_name = models.CharField(max_length=200)
>   last_name = models.CharField(max_length=200)
>   email = models.CharField(max_length=250)
>   gender = models.CharField(max_length=1, choices=gender_choices)
>   role = models.CharField(max_length=120, choices=roles_choices, 
> default="J")
>   active = models.BooleanField(default=True)
>
>   # custom manager replaces objects manger
>   all_employees = models.Manager()
>   objects = models.Manager() # The default manager.
>   active_objects = EmployeeManager() # The EmployeeManager manager.
>
>   def __str__(self):
> return str(self.first_name) + str(self.last_name)
>
> From Shell, it executes.
>
> # Employee.active_objects.all()
> # Employee.active_objects.filter(email='empl...@gmail.com 
> ')
> # Employee.active_objects.count()
>
> Source: 
> https://micropyramid.com/blog/how-to-add-a-custom-managers-in-django/
>
> When 
>
> My Query is can i show the filtered record in directly Django Admin Panel 
> after doing Login based on Logged User Username.
>
>
> -- 
>
>
> *Mr. Shetty Balaji S.Asst. ProfessorDepartment of Information Technology,*
> *SGGS Institute of Engineering & Technology, Vishnupuri, Nanded.MH.India*
> *Official: bssh...@sggs.ac.in  *
> *  Mobile: +91-9270696267*
>
>

-- 
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/91b6e1ab-735f-4824-85ad-f82640af67ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to override default Django Admin Panel Model display to Customization

2019-04-15 Thread Balaji Shetty
Hi

When i do login using Django Admin Panel , i can easily perform CRUD
operation on Models.

can i customize the display of Models Records in django Admin Panel Itself,
when I select the model, I get all the records, But i want to filter the
records based on some Criteria.

Here is my model . Code executes.



class EmployeeManager(models.Manager):
def get_queryset(self):
return super(EmployeeManager,
self).get_queryset().filter(gender='F')





class Employee(models.Model):
  gender_choices = (
   ("M", "Male"),
   ("F", "Female")
  )
  roles_choices = (
   ("J", "Junior"),
   ("S", "Senior"),
  )
  first_name = models.CharField(max_length=200)
  last_name = models.CharField(max_length=200)
  email = models.CharField(max_length=250)
  gender = models.CharField(max_length=1, choices=gender_choices)
  role = models.CharField(max_length=120, choices=roles_choices,
default="J")
  active = models.BooleanField(default=True)

  # custom manager replaces objects manger
  all_employees = models.Manager()
  objects = models.Manager() # The default manager.
  active_objects = EmployeeManager() # The EmployeeManager manager.

  def __str__(self):
return str(self.first_name) + str(self.last_name)

>From Shell, it executes.

# Employee.active_objects.all()
# Employee.active_objects.filter(email='emplo...@gmail.com')
# Employee.active_objects.count()

Source:
https://micropyramid.com/blog/how-to-add-a-custom-managers-in-django/

When

My Query is can i show the filtered record in directly Django Admin Panel
after doing Login based on Logged User Username.


-- 


*Mr. Shetty Balaji S.Asst. ProfessorDepartment of Information Technology,*
*SGGS Institute of Engineering & Technology, Vishnupuri, Nanded.MH.India*
*Official: bsshe...@sggs.ac.in  *
*  Mobile: +91-9270696267*

-- 
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/CAECSbOtQFeybd186pYSPuOThUvp3CgW7tf-p5hJzg92%2B5q84Pw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to override the ModelAdmin "change" form ?

2019-03-01 Thread Mike Dewhirst

On 2/03/2019 2:08 am, karim.at...@gmail.com wrote:

Hi Mike,

I tried what you wrote by overriding the *self.change_form_template* 
but the form does not appear.
Would you please provide me the content of your model admin 
*billing_payment_view ?*


Sure. I recently asked for assistance here and posted most of the code ...

https://groups.google.com/forum/#!topic/django-users/809HBmPa9vk

You are right, my application is different. My template contains a 
script provided by Stripe which calls their API to collect a credit card 
payment. But overall it isn't much different than any other template 
called by any other view. The view just takes a different path depending 
on whether it is a POST or a GET request. My view looks complex because 
when the user clicks [Pay now] it happens in the Stripe js embedded in 
the template and the Stripe API - in turn - hits my view with the actual 
POST containing the result of the credit card transaction. I had to seed 
the form/template with hidden data so it travelled across the Stripe 
boundary and back to me so I could complete the processing. If you can 
see past that complication it should be clear that I'm using the form to 
clean the data and the view to interface with the ORM/database.


It is working well for me now and I'm in the middle of writing unit tests.

Good luck



Thanks.

Karim

Le vendredi 1 mars 2019 00:06:40 UTC+1, Mike Dewhirst a écrit :

On 28/02/2019 9:46 pm, karim...@gmail.com  wrote:

Hi,

I'm currently struggling with a custom ModelAdmin.


Karim

I haven't tried to fully understand your use case. However, this
is what I think your process could be if you do not wish to ajax
it ...

1. Override the model save() method to call a model method which
detects your trigger scenario and calls the code you wish to
execute to collect all the data you wish to display. This might be
in the parent model or the m2m 'through' model. Unlikely to be in
the child model.

2. Write a Form to reveal the data you wish to display. It
probably needs to be a ModelForm

3. Write a template for the data including any hidden fields for
object pks and additionally consider calling {{ block.super }} to
display inherited stuff if you are extending another template and
using the same block. When I first started to work all this out I
was able to get my form to appear at the top of the ModelAdmin
form using block.super and spent a bit of time hiding the big red
[Delete] button because it was too close to my big blue [Pay now]
button. However, as I got deeper into it I somehow lost that and
never got it back. I was so pleased with getting it working
eventually that I persuaded myself I didn't really want it on the
same page anyway. Your mileage may vary :) I think you need to
hard-code the form in the ModelAdmin to get it appearing above
everything else.

4. Write any necessary urls

5. Write a view to manipulate your data, based on the request and
your form

6. Get the Admin to display it on demand. The first line of the
change_view() method below initialises the ModelAdmin to do
absolutely nothing different than usual. Nothing will happen
unless the trigger is detected. Then finally call to super to
resume the normal course of events when your code is complete.
What follows is my own recent experience. The comments should tell
you more than the code

def change_view(self, request, object_id, form_url='', extra_context=None):

     """ self = SubstanceAdmin
 request = wsgi request object
 object_id = substance
 form_url = no idea!
 extra_context = dict of apps, models, admin_urls and permissions

 https://docs.djangoproject.com/en/1.11/ref/contrib/admin/#django  
<https://docs.djangoproject.com/en/1.11/ref/contrib/admin/#django>.
 contrib.admin.ModelAdmin.change_view

     """
 # Let the ModelAdmin resume normal operations with its own template
 self.change_form_template = None
 # queryset of m2m records from the 'through' table
 ingredients = 
Substance_Ingredients.objects.filter(substance_id=object_id)
 subscription = None
 for sm2mi in ingredients:
 # sm2mi.fee_payable() is the detector which triggers the process
 payable, fee_type = sm2mi.fee_payable()  # eg., True, PAID_DATA
 if payable:
 # generate a subscription record with blank token field or
 # if one exists with a non-blank token, return None
 subscription = billing_subscribe(sm2mi, fee_type)
 if subscription:# collect money for the owner
 # switch the ModelAdmin to the new template
 self.change_form_template = 'payment.html'
 # assemble

Re: How to override the ModelAdmin "change" form ?

2019-03-01 Thread karim . atiki
Hi Mike,

I tried what you wrote by overriding the *self.change_form_template* but 
the form does not appear.
Would you please provide me the content of your model admin  
*billing_payment_view 
?*

Thanks.

Karim

Le vendredi 1 mars 2019 00:06:40 UTC+1, Mike Dewhirst a écrit :
>
> On 28/02/2019 9:46 pm, karim...@gmail.com  wrote:
>
> Hi, 
>
> I'm currently struggling with a custom ModelAdmin.
>
>
> Karim
>
> I haven't tried to fully understand your use case. However, this is what I 
> think your process could be if you do not wish to ajax it ...
>
> 1. Override the model save() method to call a model method which detects 
> your trigger scenario and calls the code you wish to execute to collect all 
> the data you wish to display. This might be in the parent model or the m2m 
> 'through' model. Unlikely to be in the child model.
>
> 2. Write a Form to reveal the data you wish to display. It probably needs 
> to be a ModelForm
>
> 3. Write a template for the data including any hidden fields for object 
> pks and additionally consider calling {{ block.super }} to display 
> inherited stuff if you are extending another template and using the same 
> block. When I first started to work all this out I was able to get my form 
> to appear at the top of the ModelAdmin form using block.super and spent a 
> bit of time hiding the big red [Delete] button because it was too close to 
> my big blue [Pay now] button. However, as I got deeper into it I somehow 
> lost that and never got it back. I was so pleased with getting it working 
> eventually that I persuaded myself I didn't really want it on the same page 
> anyway. Your mileage may vary :) I think you need to hard-code the form in 
> the ModelAdmin to get it appearing above everything else.
>
> 4. Write any necessary urls
>
> 5. Write a view to manipulate your data, based on the request and your form
>
> 6. Get the Admin to display it on demand. The first line of the 
> change_view() method below initialises the ModelAdmin to do absolutely 
> nothing different than usual. Nothing will happen unless the trigger is 
> detected. Then finally call to super to resume the normal course of events 
> when your code is complete. What follows is my own recent experience. The 
> comments should tell you more than the code
>
> def change_view(self, request, object_id, form_url='', extra_context=None):
>
> """ self = SubstanceAdmin
> request = wsgi request object
> object_id = substance
> form_url = no idea!
> extra_context = dict of apps, models, admin_urls and permissions
>
> https://docs.djangoproject.com/en/1.11/ref/contrib/admin/#django.
> contrib.admin.ModelAdmin.change_view 
>
> """
> # Let the ModelAdmin resume normal operations with its own template
> self.change_form_template = None
> # queryset of m2m records from the 'through' table
> ingredients = Substance_Ingredients.objects.filter(substance_id=object_id)
> subscription = None
> for sm2mi in ingredients:
> # sm2mi.fee_payable() is the detector which triggers the process
> payable, fee_type = sm2mi.fee_payable()  # eg., True, PAID_DATA
> if payable:
> # generate a subscription record with blank token field or
> # if one exists with a non-blank token, return None
> subscription = billing_subscribe(sm2mi, fee_type)
> if subscription:# collect money for the owner
> # switch the ModelAdmin to the new template
> self.change_form_template = 'payment.html'
> # assemble all the necessary data for the view
> context = billing_collect_context(
> sm2mi,
> subscription,
> )
> # get everything into the payment_view context
> if not extra_context:
> extra_context = dict()
> extra_context.update(self.admin_site.each_context(request))
> extra_context.update(context)
> # wrap the view to protect it with Admin permissions
> self.admin_site.admin_view(
> # call the view with request and context
> billing_payment_view(
> request,
> sm2mi,
> subscription,
> context=extra_context,
> )
> )
> # only one sm2mi at a time
> break
> return super(SubstanceAdmin, self).change_view(
> request, object_id, form_url, extra_context
> )

Re: How to override the ModelAdmin "change" form ?

2019-03-01 Thread karim . atiki
Hi Mike,

Thanks a lot for your feedback.
Your situation is quiet different from mine, BUT the way you override 
change_view and the related template will certainly help me to achieve what 
I need.
...and getting rid of dirty and unnecessary ajax calls.

I keep you posted.

Thx.

Karim

Le vendredi 1 mars 2019 00:06:40 UTC+1, Mike Dewhirst a écrit :
>
> On 28/02/2019 9:46 pm, karim...@gmail.com  wrote:
>
> Hi, 
>
> I'm currently struggling with a custom ModelAdmin.
>
>
> Karim
>
> I haven't tried to fully understand your use case. However, this is what I 
> think your process could be if you do not wish to ajax it ...
>
> 1. Override the model save() method to call a model method which detects 
> your trigger scenario and calls the code you wish to execute to collect all 
> the data you wish to display. This might be in the parent model or the m2m 
> 'through' model. Unlikely to be in the child model.
>
> 2. Write a Form to reveal the data you wish to display. It probably needs 
> to be a ModelForm
>
> 3. Write a template for the data including any hidden fields for object 
> pks and additionally consider calling {{ block.super }} to display 
> inherited stuff if you are extending another template and using the same 
> block. When I first started to work all this out I was able to get my form 
> to appear at the top of the ModelAdmin form using block.super and spent a 
> bit of time hiding the big red [Delete] button because it was too close to 
> my big blue [Pay now] button. However, as I got deeper into it I somehow 
> lost that and never got it back. I was so pleased with getting it working 
> eventually that I persuaded myself I didn't really want it on the same page 
> anyway. Your mileage may vary :) I think you need to hard-code the form in 
> the ModelAdmin to get it appearing above everything else.
>
> 4. Write any necessary urls
>
> 5. Write a view to manipulate your data, based on the request and your form
>
> 6. Get the Admin to display it on demand. The first line of the 
> change_view() method below initialises the ModelAdmin to do absolutely 
> nothing different than usual. Nothing will happen unless the trigger is 
> detected. Then finally call to super to resume the normal course of events 
> when your code is complete. What follows is my own recent experience. The 
> comments should tell you more than the code
>
> def change_view(self, request, object_id, form_url='', extra_context=None):
>
> """ self = SubstanceAdmin
> request = wsgi request object
> object_id = substance
> form_url = no idea!
> extra_context = dict of apps, models, admin_urls and permissions
>
> https://docs.djangoproject.com/en/1.11/ref/contrib/admin/#django.
> contrib.admin.ModelAdmin.change_view 
>
> """
> # Let the ModelAdmin resume normal operations with its own template
> self.change_form_template = None
> # queryset of m2m records from the 'through' table
> ingredients = Substance_Ingredients.objects.filter(substance_id=object_id)
> subscription = None
> for sm2mi in ingredients:
> # sm2mi.fee_payable() is the detector which triggers the process
> payable, fee_type = sm2mi.fee_payable()  # eg., True, PAID_DATA
> if payable:
> # generate a subscription record with blank token field or
> # if one exists with a non-blank token, return None
> subscription = billing_subscribe(sm2mi, fee_type)
> if subscription:# collect money for the owner
> # switch the ModelAdmin to the new template
> self.change_form_template = 'payment.html'
> # assemble all the necessary data for the view
> context = billing_collect_context(
> sm2mi,
> subscription,
> )
> # get everything into the payment_view context
> if not extra_context:
> extra_context = dict()
> extra_context.update(self.admin_site.each_context(request))
> extra_context.update(context)
> # wrap the view to protect it with Admin permissions
> self.admin_site.admin_view(
> # call the view with request and context
> billing_payment_view(
> request,
> sm2mi,
> subscription,
> context=extra_context,
> )
> )
> # only one sm2mi at a time
> break
> return super(SubstanceAdmin, self).change_vi

Re: How to override the ModelAdmin "change" form ?

2019-02-28 Thread Mike Dewhirst

  
  
On 28/02/2019 9:46 pm,
  karim.at...@gmail.com wrote:


  
  Hi,


I'm currently struggling with a custom ModelAdmin.
  


Karim

I haven't tried to fully understand your use case. However, this is
what I think your process could be if you do not wish to ajax it ...

1. Override the model save() method to call a model method which
detects your trigger scenario and calls the code you wish to execute
to collect all the data you wish to display. This might be in the
parent model or the m2m 'through' model. Unlikely to be in the child
model.

2. Write a Form to reveal the data you wish to display. It probably
needs to be a ModelForm

3. Write a template for the data including any hidden fields for
object pks and additionally consider calling {{ block.super }} to
display inherited stuff if you are extending another template and
using the same block. When I first started to work all this out I
was able to get my form to appear at the top of the ModelAdmin form
using block.super and spent a bit of time hiding the big red
[Delete] button because it was too close to my big blue [Pay now]
button. However, as I got deeper into it I somehow lost that and
never got it back. I was so pleased with getting it working
eventually that I persuaded myself I didn't really want it on the
same page anyway. Your mileage may vary :) I think you need to
hard-code the form in the ModelAdmin to get it appearing above
everything else.

4. Write any necessary urls

5. Write a view to manipulate your data, based on the request and
your form

6. Get the Admin to display it on demand. The first line of the
change_view() method below initialises the ModelAdmin to do
absolutely nothing different than usual. Nothing will happen unless
the trigger is detected. Then finally call to super to resume the
normal course of events when your code is complete. What follows is
my own recent experience. The comments should tell you more than the
code

def change_view(self, request, object_id, form_url='', extra_context=None):
    """ self = SubstanceAdmin
request = wsgi request object
object_id = substance
form_url = no idea!
extra_context = dict of apps, models, admin_urls and permissions

https://docs.djangoproject.com/en/1.11/ref/contrib/admin/#django.
contrib.admin.ModelAdmin.change_view 

    """
# Let the ModelAdmin resume normal operations with its own template
    self.change_form_template = None
# queryset of m2m records from the 'through' table
ingredients = Substance_Ingredients.objects.filter(substance_id=object_id)
subscription = None
for sm2mi in ingredients:
# sm2mi.fee_payable() is the detector which triggers the process
payable, fee_type = sm2mi.fee_payable()  # eg., True, PAID_DATA
if payable:
# generate a subscription record with blank token field or
# if one exists with a non-blank token, return None
subscription = billing_subscribe(sm2mi, fee_type)
if subscription:# collect money for the owner
# switch the ModelAdmin to the new template
self.change_form_template = 'payment.html'
# assemble all the necessary data for the view
context = billing_collect_context(
sm2mi,
subscription,
)
# get everything into the payment_view context
if not extra_context:
extra_context = dict()
extra_context.update(self.admin_site.each_context(request))
extra_context.update(context)
# wrap the view to protect it with Admin permissions
self.admin_site.admin_view(
# call the view with request and context
billing_payment_view(
request,
sm2mi,
subscription,
context=extra_context,
)
)
# only one sm2mi at a time
break
return super(SubstanceAdmin, self).change_view(
request, object_id, form_url, extra_context
)



 
7. Call super in the model save() method *or* raise an exception to
prevent saving. I'm actually not sure about this bit. It may go
against the Django flow. However, I do use a BusinessRuleViolation
exception which inherits from ValidationError and therefore lets me
include a human readable message which appears in the Admin and
*seems* to prevent saving. You would need to test this especially
with m2m side-effects and atomicity consequences.

I 

Re: How to override the ModelAdmin "change" form ?

2019-02-28 Thread Nelson Varela
You maybe want a model admin view where you can send the user to and 
collect the data you want to comare and show warnings

-- 
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/2b4e6166-2f8a-40f0-9f0d-a5c7c8df494e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to override the ModelAdmin "change" form ?

2019-02-28 Thread karim . atiki
Hi,

I'm currently struggling with a custom ModelAdmin.

Considering the following model:


# Bloc fonctionnel
class Assembly(Item):

product = models.ForeignKey(to='ProductFamily', on_delete=models.CASCADE
, null=True, verbose_name=_('Famille Produit'))
functions = models.ManyToManyField(Function, verbose_name=_('Fonctions'
))
*performances* = models.ManyToManyField(Performance, verbose_name=_(
'Performances'), related_name='performances')

def _get_type(self):
return ItemType.ASSEMBLY

class Meta:
verbose_name = _('Bloc Fonctionnel')
verbose_name_plural = _('Blocs Fonctionnels')



I have a custom AssemblyAdmin related to it and also a custom AssemblyForm 
for customizing some fieds.

The *performances* m2m field is critical.  
The performances are captured in the form with a dynamic_raw_id field, 
which works fine.

But when this field is modified, some updates/deletions might be applied in 
other tables of the database.
For this purpose, I need to collect the "performance" pk captured in the 
html form and compare them with those currently in the database.

Basically, when the user clicks on the regular "Save" or "Save and 
continue" button, I would need to display an alert form (like when you 
click on the delete button) to explain what would happen.

I struggled with some ajax routines but it does not work as expected. 

I don't know if it's really doable and how to achieve it.

Any suggestion is welcome.

Cheers.

Z.







-- 
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/88135218-a965-46c8-a454-c0376a5682f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can I define classes in Django settings, and how can I override such settings in tests?

2018-12-27 Thread Derek
You don't need to create a class; you can just define new settings in the 
settings file.

For example, I have added a setting called CUSTOMER.  I could have logic 
which defines other behavior based on that:

from django.conf import settings
if setttings.CUSTOMER == 'ABC Corp':
logo = 'ABC'
else:
logo = 'generic'

Your classes can use also directly use these settings in a similar way 

On Thursday, 27 December 2018 10:18:28 UTC+2, Uri Even-Chen wrote:
>
> Hi,
>
> We are using Django for Speedy Net and Speedy Match 
> <https://github.com/speedy-net/speedy-net> (currently Django 1.11.17, we 
> can't upgrade to a newer version of Django because of one of our 
> requirements, django-modeltranslation). I want to define some of our 
> settings as classes. For example:
>
> class UserSettings(object):
> MIN_USERNAME_LENGTH = 6
> MAX_USERNAME_LENGTH = 40
>
> MIN_SLUG_LENGTH = 6
> MAX_SLUG_LENGTH = 200
>
> # Users can register from age 0 to 180, but can't be kept on the site 
> after age 250.
> MIN_AGE_ALLOWED_IN_MODEL = 0  # In years.
> MAX_AGE_ALLOWED_IN_MODEL = 250  # In years.
>
> MIN_AGE_ALLOWED_IN_FORMS = 0  # In years.
> MAX_AGE_ALLOWED_IN_FORMS = 180  # In years.
>
> MIN_PASSWORD_LENGTH = 8
> MAX_PASSWORD_LENGTH = 120
>
> PASSWORD_VALIDATORS = [
> {
> 'NAME': 'speedy.core.accounts.validators.PasswordMinLengthValidator',
> },
> {
> 'NAME': 'speedy.core.accounts.validators.PasswordMaxLengthValidator',
> },
> ]
>
> (which is defined in 
> https://github.com/speedy-net/speedy-net/blob/uri_merge_with_master_2018-12-26_a/speedy/net/settings/global_settings.py).
>  
> And then in the models, I tried to use:
>
> from django.conf import settings as django_settings
>
> class User(ValidateUserPasswordMixin, PermissionsMixin, Entity, 
> AbstractBaseUser):
> settings = django_settings.UserSettings
>
> (and then use attributes of `settings`, such as 
> `settings.MIN_USERNAME_LENGTH`, in the class).
>
> But it throws an exception
>
> AttributeError: 'Settings' object has no attribute 'UserSettings'
>
> (but it doesn't throw an exception if I use there a constant which is not 
> a class).
>
> This is the first problem. In the meantime, I defined instead:
>
> from speedy.net.settings import global_settings as 
> speedy_net_global_settings
>
> class User(ValidateUserPasswordMixin, PermissionsMixin, Entity, 
> AbstractBaseUser):
> settings = speedy_net_global_settings.UserSettings
>
> The second problem, is how do I override such settings in tests? For 
> example, I use the following code:
>
> from speedy.core.settings import tests as tests_settings
>
>
> @override_settings(MAX_NUMBER_OF_FRIENDS_ALLOWED=tests_settings.OVERRIDE_MAX_NUMBER_OF_FRIENDS_ALLOWED)
>
> in 
> https://github.com/speedy-net/speedy-net/blob/uri_merge_with_master_2018-12-26_a/speedy/core/friends/tests/test_views.py.
>  
> But if `MAX_NUMBER_OF_FRIENDS_ALLOWED` would be defined in the class 
> `UserSettings`, how do I override it?
>
> Thanks,
> אורי (Uri)
> u...@speedy.net 
>

-- 
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/a47584ec-6fdd-40a4-b795-1d8a140ab935%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can I define classes in Django settings, and how can I override such settings in tests?

2018-12-27 Thread Ira Abbott
You need an instance to evaluate member variables.   These are mutable, so can 
be different per instance.

Settings should use a dictionary.

Sent from my iPhone

> On Dec 27, 2018, at 3:15 AM, אורי  wrote:
> 
> Hi,
> 
> We are using Django for Speedy Net and Speedy Match (currently Django 
> 1.11.17, we can't upgrade to a newer version of Django because of one of our 
> requirements, django-modeltranslation). I want to define some of our settings 
> as classes. For example:
> 
>   class UserSettings(object):
>   MIN_USERNAME_LENGTH = 6
>   MAX_USERNAME_LENGTH = 40
> 
>   MIN_SLUG_LENGTH = 6
>   MAX_SLUG_LENGTH = 200
> 
>   # Users can register from age 0 to 180, but can't be kept on 
> the site after age 250.
>   MIN_AGE_ALLOWED_IN_MODEL = 0  # In years.
>   MAX_AGE_ALLOWED_IN_MODEL = 250  # In years.
> 
>   MIN_AGE_ALLOWED_IN_FORMS = 0  # In years.
>   MAX_AGE_ALLOWED_IN_FORMS = 180  # In years.
> 
>   MIN_PASSWORD_LENGTH = 8
>   MAX_PASSWORD_LENGTH = 120
> 
>   PASSWORD_VALIDATORS = [
>   {
>   'NAME': 
> 'speedy.core.accounts.validators.PasswordMinLengthValidator',
>   },
>   {
>   'NAME': 
> 'speedy.core.accounts.validators.PasswordMaxLengthValidator',
>   },
>   ]
> 
> (which is defined in 
> https://github.com/speedy-net/speedy-net/blob/uri_merge_with_master_2018-12-26_a/speedy/net/settings/global_settings.py).
>  And then in the models, I tried to use:
> 
>   from django.conf import settings as django_settings
> 
>   class User(ValidateUserPasswordMixin, PermissionsMixin, Entity, 
> AbstractBaseUser):
>   settings = django_settings.UserSettings
> 
> (and then use attributes of `settings`, such as 
> `settings.MIN_USERNAME_LENGTH`, in the class).
> 
> But it throws an exception
> 
>   AttributeError: 'Settings' object has no attribute 'UserSettings'
> 
> (but it doesn't throw an exception if I use there a constant which is not a 
> class).
> 
> This is the first problem. In the meantime, I defined instead:
> 
>   from speedy.net.settings import global_settings as 
> speedy_net_global_settings
> 
>   class User(ValidateUserPasswordMixin, PermissionsMixin, Entity, 
> AbstractBaseUser):
>   settings = speedy_net_global_settings.UserSettings
> 
> The second problem, is how do I override such settings in tests? For example, 
> I use the following code:
> 
>   from speedy.core.settings import tests as tests_settings
> 
>   
> @override_settings(MAX_NUMBER_OF_FRIENDS_ALLOWED=tests_settings.OVERRIDE_MAX_NUMBER_OF_FRIENDS_ALLOWED)
> 
> in 
> https://github.com/speedy-net/speedy-net/blob/uri_merge_with_master_2018-12-26_a/speedy/core/friends/tests/test_views.py.
>  But if `MAX_NUMBER_OF_FRIENDS_ALLOWED` would be defined in the class 
> `UserSettings`, how do I override it?
> 
> Thanks,
> אורי (Uri)
> u...@speedy.net
> -- 
> 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/CABD5YeFfW-JbXawLmxX2aUjD41qS90CF7PbzUMwn0uqSWVwt7w%40mail.gmail.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/A443C25D-738E-4F49-9D4F-43CCA03F3FC7%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Can I define classes in Django settings, and how can I override such settings in tests?

2018-12-27 Thread אורי
Hi,

We are using Django for Speedy Net and Speedy Match
<https://github.com/speedy-net/speedy-net> (currently Django 1.11.17, we
can't upgrade to a newer version of Django because of one of our
requirements, django-modeltranslation). I want to define some of our
settings as classes. For example:

class UserSettings(object):
MIN_USERNAME_LENGTH = 6
MAX_USERNAME_LENGTH = 40

MIN_SLUG_LENGTH = 6
MAX_SLUG_LENGTH = 200

# Users can register from age 0 to 180, but can't be kept on the site after
age 250.
MIN_AGE_ALLOWED_IN_MODEL = 0  # In years.
MAX_AGE_ALLOWED_IN_MODEL = 250  # In years.

MIN_AGE_ALLOWED_IN_FORMS = 0  # In years.
MAX_AGE_ALLOWED_IN_FORMS = 180  # In years.

MIN_PASSWORD_LENGTH = 8
MAX_PASSWORD_LENGTH = 120

PASSWORD_VALIDATORS = [
{
'NAME': 'speedy.core.accounts.validators.PasswordMinLengthValidator',
},
{
'NAME': 'speedy.core.accounts.validators.PasswordMaxLengthValidator',
},
]

(which is defined in
https://github.com/speedy-net/speedy-net/blob/uri_merge_with_master_2018-12-26_a/speedy/net/settings/global_settings.py).
And then in the models, I tried to use:

from django.conf import settings as django_settings

class User(ValidateUserPasswordMixin, PermissionsMixin, Entity,
AbstractBaseUser):
settings = django_settings.UserSettings

(and then use attributes of `settings`, such as
`settings.MIN_USERNAME_LENGTH`, in the class).

But it throws an exception

AttributeError: 'Settings' object has no attribute 'UserSettings'

(but it doesn't throw an exception if I use there a constant which is not a
class).

This is the first problem. In the meantime, I defined instead:

from speedy.net.settings import global_settings as
speedy_net_global_settings

class User(ValidateUserPasswordMixin, PermissionsMixin, Entity,
AbstractBaseUser):
settings = speedy_net_global_settings.UserSettings

The second problem, is how do I override such settings in tests? For
example, I use the following code:

from speedy.core.settings import tests as tests_settings

@override_settings(MAX_NUMBER_OF_FRIENDS_ALLOWED=tests_settings.OVERRIDE_MAX_NUMBER_OF_FRIENDS_ALLOWED)

in
https://github.com/speedy-net/speedy-net/blob/uri_merge_with_master_2018-12-26_a/speedy/core/friends/tests/test_views.py.
But if `MAX_NUMBER_OF_FRIENDS_ALLOWED` would be defined in the class
`UserSettings`, how do I override it?

Thanks,
אורי (Uri)
u...@speedy.net

-- 
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/CABD5YeFfW-JbXawLmxX2aUjD41qS90CF7PbzUMwn0uqSWVwt7w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Problem when override admin template whit project name have both capital and small letters

2018-12-26 Thread EaiLFly Bai
I just found a behavior  not expected, but I'm not sure it by design or a 
bug.
Let's say we have a Django project named iNOC and a model NewIncident, I 
need to override some template such as change_form.html /change_list.html  
and submit_line.html, if I put this three file in 
path'iNOC/templates/admin/inoc/newincident'only submit_line.html works, 
change_form and change_list need be put in 
path'iNOC/templates/admin/iNOC/newincident' then it will take effect, 
Just what to know if this is by design or it's a bug?
And my platform is centos, so it's case sensitive.

-- 
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/2ec0558a-d5f9-492a-9272-eaa7be913a43%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to override the javascript default editable bootstap values in Django

2018-09-17 Thread Srinivas Gadi
Can someone please help me with this?

On Sun, Sep 16, 2018 at 4:07 PM Srinivas Gadi  wrote:

>  am stuck at overriding the default editable bootstrap values in Django
> framework javascript HTML page
>
> In my webpage, it coded as below
>
>
> $.fn.editable.defaults.url = "{% url 'page1' model.PATH %}";
>
>
> Now my requirement is, When I click on a button, it check the
> views.py(page1, which is default URL) and pass the context through 'return
> HttpResponse' to html page that "True" or "False" based the value, if
> false, it should go page2, it never goes to page2 url, its entered to the
> function conflict_warn() but not inside and eventually it failed with 
> the,Uncaught
> TypeError:e.getAttribute is not a function I tried number of ways, but
> all are vain.
>
>
> $(this).editable({
> value: "",
> display: false,
> success: function (response, newValue) {
> if (response.hasOwnProperty("State"))){
> conflict_warn(response, newValue)//if State value True,should go to other 
> func
> }
> else {
> window.location.href = "{% url 'path1' 'path2'%}" + response;
> }
> },
> error: function(response, newValue) { $(this).editable("destroy"); }
> });
> $(this).editable("submit");
>
>
> function conflict_warn(response, newValue) {
> $(this).editable({
> value: ""
> display: false
> success: function (response.newvalue) {
> window.location.href = "{% url 'path1' 'path2'%}" + response;
> }
> });
> $(this).editable("setValue", "{% url 'page1' model.PATH %}");
> $(this).editable("submit");
> }
>
>
>
> --
> 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/f27486fd-7b8a-4286-9c3a-25a73f40250d%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Srinivas .G
  9966559383

-- 
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/CAPC7sphqe6jS4mR_T8MGTb6hOr-d6XSbZMptN6N%3DTwCwEofn%2Bw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


How to override the java script default editable bootstrap values in Django

2018-09-16 Thread Srinivas Gadi


I am stuck at overriding the default editable bootstrap values in Django 
framework javascript html page

In my webpage, it coded as below

$.fn.editable.defaults.url = "{% url 'page1' model.PATH %}";

Now my requirement is, When I click on a button, it check the 
views.py(page1, which is default URL) and pass the context through 'return 
HttpResponse' to html page that "True" or "False" based the value, if 
false, it should go page2, it never goes to page2 url, its entered to the 
function conflict_warn() but not inside and eventually it failed with 
the,Uncaught 
TypeError:e.getAttribute is not a function I tried number of ways, but all 
are vain.

$(this).editable({
value: "",
display: false,
success: function (response, newValue) {
if (response.hasOwnProperty("State"))){
conflict_warn(response, newValue)//if State value True,should go to other 
func}
else {
window.location.href = "{% url 'path1' 'path2'%}" + response;}
},
error: function(response, newValue) { $(this).editable("destroy"); }
});
$(this).editable("submit");

function conflict_warn(response, newValue) {
$(this).editable({
value: ""
display: false
success: function (response.newvalue) {
window.location.href = "{% url 'path1' 'path2'%}" + response;
}
});
$(this).editable("setValue", "{% url 'page1' model.PATH %}");
$(this).editable("submit");}

-- 
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/54a49b08-2559-4ad8-b096-cf851ca6af73%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to override the javascript default editable bootstap values in Django

2018-09-16 Thread Srinivas Gadi


 am stuck at overriding the default editable bootstrap values in Django 
framework javascript HTML page

In my webpage, it coded as below


$.fn.editable.defaults.url = "{% url 'page1' model.PATH %}";


Now my requirement is, When I click on a button, it check the 
views.py(page1, which is default URL) and pass the context through 'return 
HttpResponse' to html page that "True" or "False" based the value, if 
false, it should go page2, it never goes to page2 url, its entered to the 
function conflict_warn() but not inside and eventually it failed with 
the,Uncaught 
TypeError:e.getAttribute is not a function I tried number of ways, but all 
are vain.


$(this).editable({
value: "",
display: false,
success: function (response, newValue) {
if (response.hasOwnProperty("State"))){
conflict_warn(response, newValue)//if State value True,should go to other 
func
}
else {
window.location.href = "{% url 'path1' 'path2'%}" + response;
}
},
error: function(response, newValue) { $(this).editable("destroy"); }
});
$(this).editable("submit");


function conflict_warn(response, newValue) {
$(this).editable({
value: ""
display: false
success: function (response.newvalue) {
window.location.href = "{% url 'path1' 'path2'%}" + response;
}
});
$(this).editable("setValue", "{% url 'page1' model.PATH %}");
$(this).editable("submit");
}



-- 
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/f27486fd-7b8a-4286-9c3a-25a73f40250d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: SwaggerUI template override

2018-08-21 Thread Christian
I got it , it works as it is described, my fault.

Am Sonntag, 19. August 2018 17:57:15 UTC+2 schrieb Christian:
>
> Hi,
>
> I'm trying to use a customized version of index as describe here-
>
> https://django-rest-swagger.readthedocs.io/en/latest/customization/#customization
>
> I tried different places and settings in the TEMPLATE settings.py, but It 
> won't work.
>
>
> Thanks in advance
> Christian
>
>
>

-- 
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/a04b6c7a-e688-4268-a4a4-d111822abcc1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


SwaggerUI template override

2018-08-19 Thread Christian
Hi,

I'm trying to use a customized version of index as describe here-
https://django-rest-swagger.readthedocs.io/en/latest/customization/#customization

I tried different places and settings in the TEMPLATE settings.py, but It 
won't work.


Thanks in advance
Christian


-- 
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/f00956a2-3d1a-4172-b9a6-0d93264ed42c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trouble raising forms.ValidationError in save() override in admin.py

2018-05-03 Thread Gonzalo Amadio
This is very old, but in the case someone red this.

If you do it on the save method of the admin, you MUST save the model.

So you should override admin's form. 

Check it here how to do it : http://itegram.com/2018/05/03/
add-extra-control-to-admin-save-method/ 
<http://itegram.com/?p=11972=true>

El jueves, 31 de marzo de 2011, 8:10:40 (UTC-3), Daniel Roseman escribió:
>
> On Thursday, March 31, 2011 11:09:17 AM UTC+1, Lloyd Dube wrote:
>>
>> Hi Shawn,
>>
>> Thanks for the feedback. I read the docs and defined a clean_audio_file 
>> method in my ModelAdmin class.
>
>
> That's not what the docs say. They say you should create it on the Form. 
> And where did you get the idea that the clean method takes any of those 
> parameters?
> --
> DR.
>

-- 
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/b73a0f49-2716-42f1-b026-6dd3a935d8fb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Admin Form clean method override only working for one exception

2018-01-04 Thread dean raemaekers
Thanks Julio!

This worked.

On Thursday, January 4, 2018 at 2:59:16 PM UTC+2, Julio Biason wrote:
>
> Hi Dean,
>
> You forgot to call the form clean method (the first line after your `def 
> clean` should be `super().clean()` as shown in the documentation: 
> https://docs.djangoproject.com/en/2.0/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other
> ).
>
> On Thu, Jan 4, 2018 at 7:06 AM, dean raemaekers <dp.rae...@gmail.com 
> > wrote:
>
>> Hello,
>>
>> I am trying to override the Forms in the Django Admin interface to have 
>> custom exceptions in the clean() method.
>>
>> This works for my first validation, but it doesn't work for a second one 
>> in the same form, or on another form at all. I am wondering if I have the 
>> syntax wrong for multiple validations.
>>
>> The code looks like this:
>>
>> class ProviderForm(forms.ModelForm):
>> class Meta:
>> model = Provider
>> fields = '__all__'
>>
>> def clean(self):
>> #provider start date and end date
>> provider_start_date = self.cleaned_data.get('provider_start_date')
>> provider_end_date = self.cleaned_data.get('provider_end_date')
>> if provider_start_date > provider_end_date:
>> raise forms.ValidationError("Start date can't be after end date")
>>
>> #etqe_id and provider_code
>> provider_etqe_id = self.cleaned_data.get('provider_etqe_id')
>> provider_code = self.cleaned_data.get('provider_code')
>> if "HW" not in provider_code:
>> raise forms.ValidationError("Invalid provider code")
>>
>> if "9" not in provider_etqe_id:
>> raise forms.ValidationError("Invalid ETQE ID") 
>>
>> return self.cleaned_data
>>
>> class ProviderAdmin(admin.ModelAdmin):
>> form = ProviderForm
>>
>> admin.site.register(Provider, ProviderAdmin)
>>
>> (The first validation, the start date and end date, does work perfectly - 
>> the second validation does not work at all, and allows the form to be saved 
>> no matter what data is entered)
>>
>> Then I also have replicated this for another form:
>>
>> class PersonForm(forms.ModelForm):
>> class Meta:
>> model = Person
>> fields = '__all__'
>>
>> def clean(self):
>>
>> person_alternate_id = self.cleaned_data.get('person_alternate_id')
>> alternate_id_type_id = self.cleaned_data.get('alternate_id_type_id') 
>>
>> if person_alternate_id is not None and alternate_id_type_id == 533:
>> raise forms.ValidationError("Person Alternate ID is not blank, therefore 
>> Alternate ID Type ID cannot be 533")
>> if person_alternate_id is None and alternate_id_type_id != 533:
>> raise forms.ValidationError("Person Alternate ID is blank, therefore 
>> Alternate ID Type ID must be 533")
>>
>> return self.cleaned_data
>>
>> class PersonAdmin(admin.ModelAdmin):
>> form = PersonForm
>>
>> admin.site.register(Person, PersonAdmin)
>>
>> This does not work at all, and also allows the form to be saved even if 
>> the invalid data has been entered.
>>
>> Thanks in advance!
>>
>> -- 
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/6d1e21bc-cc16-42bd-a9b9-949a800c81b7%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/6d1e21bc-cc16-42bd-a9b9-949a800c81b7%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> *Julio Biason*, Sofware Engineer
> *AZION*  |  Deliver. Accelerate. Protect.
> Office: +55 51 3083 8101  |  Mobile: +55 51 *99907 0554*
>

-- 
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/4cf452a6-1232-43d6-9ae0-1ddd310db98e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Admin Form clean method override only working for one exception

2018-01-04 Thread Julio Biason
Hi Dean,

You forgot to call the form clean method (the first line after your `def
clean` should be `super().clean()` as shown in the documentation:
https://docs.djangoproject.com/en/2.0/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other
).

On Thu, Jan 4, 2018 at 7:06 AM, dean raemaekers <dp.raemaek...@gmail.com>
wrote:

> Hello,
>
> I am trying to override the Forms in the Django Admin interface to have
> custom exceptions in the clean() method.
>
> This works for my first validation, but it doesn't work for a second one
> in the same form, or on another form at all. I am wondering if I have the
> syntax wrong for multiple validations.
>
> The code looks like this:
>
> class ProviderForm(forms.ModelForm):
> class Meta:
> model = Provider
> fields = '__all__'
>
> def clean(self):
> #provider start date and end date
> provider_start_date = self.cleaned_data.get('provider_start_date')
> provider_end_date = self.cleaned_data.get('provider_end_date')
> if provider_start_date > provider_end_date:
> raise forms.ValidationError("Start date can't be after end date")
>
> #etqe_id and provider_code
> provider_etqe_id = self.cleaned_data.get('provider_etqe_id')
> provider_code = self.cleaned_data.get('provider_code')
> if "HW" not in provider_code:
> raise forms.ValidationError("Invalid provider code")
>
> if "9" not in provider_etqe_id:
> raise forms.ValidationError("Invalid ETQE ID")
>
> return self.cleaned_data
>
> class ProviderAdmin(admin.ModelAdmin):
> form = ProviderForm
>
> admin.site.register(Provider, ProviderAdmin)
>
> (The first validation, the start date and end date, does work perfectly -
> the second validation does not work at all, and allows the form to be saved
> no matter what data is entered)
>
> Then I also have replicated this for another form:
>
> class PersonForm(forms.ModelForm):
> class Meta:
> model = Person
> fields = '__all__'
>
> def clean(self):
>
> person_alternate_id = self.cleaned_data.get('person_alternate_id')
> alternate_id_type_id = self.cleaned_data.get('alternate_id_type_id')
>
> if person_alternate_id is not None and alternate_id_type_id == 533:
> raise forms.ValidationError("Person Alternate ID is not blank, therefore
> Alternate ID Type ID cannot be 533")
> if person_alternate_id is None and alternate_id_type_id != 533:
> raise forms.ValidationError("Person Alternate ID is blank, therefore
> Alternate ID Type ID must be 533")
>
> return self.cleaned_data
>
> class PersonAdmin(admin.ModelAdmin):
> form = PersonForm
>
> admin.site.register(Person, PersonAdmin)
>
> This does not work at all, and also allows the form to be saved even if
> the invalid data has been entered.
>
> Thanks in advance!
>
> --
> 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/6d1e21bc-cc16-42bd-a9b9-949a800c81b7%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/6d1e21bc-cc16-42bd-a9b9-949a800c81b7%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Julio Biason*, Sofware Engineer
*AZION*  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101 <callto:+555130838101>  |  Mobile: +55 51
<callto:+5551996209291>*99907 0554*

-- 
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/CAEM7gE0s%2BVYVknpZ3wj%3DdCqh%2BAwM6kB%3D-9joA8xdu-4PhXqJ-g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django Admin Form clean method override only working for one exception

2018-01-04 Thread dean raemaekers
Hello,

I am trying to override the Forms in the Django Admin interface to have 
custom exceptions in the clean() method.

This works for my first validation, but it doesn't work for a second one in 
the same form, or on another form at all. I am wondering if I have the 
syntax wrong for multiple validations.

The code looks like this:

class ProviderForm(forms.ModelForm):
class Meta:
model = Provider
fields = '__all__'

def clean(self):
#provider start date and end date
provider_start_date = self.cleaned_data.get('provider_start_date')
provider_end_date = self.cleaned_data.get('provider_end_date')
if provider_start_date > provider_end_date:
raise forms.ValidationError("Start date can't be after end date")

#etqe_id and provider_code
provider_etqe_id = self.cleaned_data.get('provider_etqe_id')
provider_code = self.cleaned_data.get('provider_code')
if "HW" not in provider_code:
raise forms.ValidationError("Invalid provider code")

if "9" not in provider_etqe_id:
raise forms.ValidationError("Invalid ETQE ID") 

return self.cleaned_data

class ProviderAdmin(admin.ModelAdmin):
form = ProviderForm

admin.site.register(Provider, ProviderAdmin)

(The first validation, the start date and end date, does work perfectly - 
the second validation does not work at all, and allows the form to be saved 
no matter what data is entered)

Then I also have replicated this for another form:

class PersonForm(forms.ModelForm):
class Meta:
model = Person
fields = '__all__'

def clean(self):

person_alternate_id = self.cleaned_data.get('person_alternate_id')
alternate_id_type_id = self.cleaned_data.get('alternate_id_type_id') 

if person_alternate_id is not None and alternate_id_type_id == 533:
raise forms.ValidationError("Person Alternate ID is not blank, therefore 
Alternate ID Type ID cannot be 533")
if person_alternate_id is None and alternate_id_type_id != 533:
raise forms.ValidationError("Person Alternate ID is blank, therefore 
Alternate ID Type ID must be 533")

return self.cleaned_data

class PersonAdmin(admin.ModelAdmin):
form = PersonForm

admin.site.register(Person, PersonAdmin)

This does not work at all, and also allows the form to be saved even if the 
invalid data has been entered.

Thanks in advance!

-- 
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/6d1e21bc-cc16-42bd-a9b9-949a800c81b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


override default "go back" action on a web page to go back to main menu

2017-09-27 Thread fábio andrews rocha marques
Let's say i have a "register a new user" View and on this page, when the 
user forgets to inform a password or a username, i show a message to him on 
the same page saying "you forgot the password". The way i do this is by 
doing this(on my View.py in a function called cadastrarprofessor):

nomeusuario = request.POST['usuario'] #username
nomesenha = request.POST['senha'] #password
nomeemail = request.POST['email'] #email

if not nomeusuario:
return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': 
False, 'error_message': "informe um usuário", 
'nomeemailcadastro':nomeemail, 'nomesenhacadastro':nomesenha})
elif not nomesenha:
return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': 
False, 'error_message': "informe uma senha", 'nomeemailcadastro':nomeemail, 
'nomeusuariocadastro':nomeusuario})
elif not nomeemail:
return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': 
False, 'error_message': "informe um email", 'nomesenhacadastro':nomesenha, 
'nomeusuariocadastro':nomeusuario})

And my template for this page(cadastro.html) is like this:

Cadastro

{% csrf_token %}
Usuário: 
{% if nomeusuariocadastro %}

{% else %}

{% endif %}


... (DO THE SAME TO SENHA/PASSWORD AND EMAIL)





{% csrf_token %}

{% if cadastrorealizadocomsucesso is True %}cadastro realizado com 
sucesso!{% endif %}
{% if error_message %}{{ error_message }}{% endif %}

So, every time the user forgets to mention a username or email or password 
in this screen, i use render to redirect the user to the same page but this 
time displaying a error_message. Let's say he did forget to fill the 
textfield with a username... he goes back to the same page and sees the 
error message. After that, let's say everything is right and he finally 
registers a new user, he sees "cadastro realizado com sucesso"(sucessfully 
registered new user) and stays on the same page. But when he goes back a 
page, instead of going back to the page before the cadastro.html, he goes 
back to the same page cadastro.html but displaying the error message for 
the "you forgot to mention your username". I don't want him to go back to 
the same page with error message, i want to make him go back to my main 
menu. 
Is there any way to override the current page "go back" action? Is there a 
better approach to display error messages on the same page instead of using:
return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 
'error_message': "informe um usuário", 'nomeemailcadastro':nomeemail, 
'nomesenhacadastro':nomesenha})
?




-- 
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/c6a0809a-21e4-4af8-b674-b8ae27f724c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: forms.Form.to_div ? and how override forms.Boundfield.label_tag?

2017-07-27 Thread Dan Tagg
crispy forms is a good addition for form creation
http://django-crispy-forms.readthedocs.io/en/latest/.

It gives you a lot of control over layout and templating.

Dan

On 26 July 2017 at 13:02, threesixright <threesixri...@gmail.com> wrote:

> Hi All,
>
> Just started a few weeks ago with (v1.11) *Django* (coming from Rails)
> and I *love* it! Kudos to all the dev's!
>
> I'm fiddling with creating forms. What would be the best approach to add a
> *to_div* method to the *forms.Form* class ? many frameworks (bootstrap,
> semantic-ui, etc.)  are using:
>
>  https://semantic-ui.com/modules/checkbox.html>">  tabindex="0" class="hidden"> I agree to the Terms and Conditions label> 
> 
>
> ..to group fields (label + input).
>
> I understand I can make my own form template and just loop over the
> fields. But nicer would be (imo) if you can use a *to_div* method om the
> form.
>
> Another thing I ran into is the usage of the form label. Unlike the input
> fields that you can easily override via the widget html templates, the
> label you can not. This is implemented in the *Boundfield* *label_tag*
> method. What would be the best way to change its default behaviour?
>
> Thanks!
> 36R
>
> --
> 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/d5a2df9b-e9ea-4cd6-8fb2-355a38bacd03%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/d5a2df9b-e9ea-4cd6-8fb2-355a38bacd03%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Wildman and Herring Limited, Registered Office: 28 Brock Street, Bath,
United Kingdom, BA1 2LN, Company no: 05766374

-- 
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/CAPZHCY57G%3DT3Hnm8wgp4-BhWnFLiOLFQF_UPMFaqAp7n-w2XtA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


forms.Form.to_div ? and how override forms.Boundfield.label_tag?

2017-07-26 Thread threesixright
Hi All,

Just started a few weeks ago with (v1.11) *Django* (coming from Rails) and 
I *love* it! Kudos to all the dev's!

I'm fiddling with creating forms. What would be the best approach to add a 
*to_div* method to the *forms.Form* class ? many frameworks (bootstrap, 
semantic-ui, etc.)  are using:

 https://semantic-ui.com/modules/checkbox.html>">  I agree to the Terms and Conditions 


..to group fields (label + input). 

I understand I can make my own form template and just loop over the fields. 
But nicer would be (imo) if you can use a *to_div* method om the form. 

Another thing I ran into is the usage of the form label. Unlike the input 
fields that you can easily override via the widget html templates, the 
label you can not. This is implemented in the *Boundfield* *label_tag* 
method. What would be the best way to change its default behaviour?

Thanks!
36R

-- 
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/d5a2df9b-e9ea-4cd6-8fb2-355a38bacd03%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Unable to override map_template in OSMGeoAdmin in django 1.11.3

2017-07-14 Thread Chew Kok Hoor (gMail)
Hi,

I tried overriding the map template using bold line below:
class LocationAdmin(geo_admin.OSMGeoAdmin):
form = LocationForm
map_template = 'gis/admin/google.html

In my settings.py I have added my folder:

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates')
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.static',
],
'debug': DEBUG
},
}
]

and my files are properly located:



However, when my admin page loads, it seems to not load from my template but 
instead load from django/forms/templates/ (as per error).

Template-loader postmortem

Django tried loading these templates, in this order:

Using engine django:
django.template.loaders.filesystem.Loader: 
***/lib/python2.7/site-packages/django/forms/templates/gis/admin/google.html 
(Source does not exist)
django.template.loaders.app_directories.Loader: 
***/lib/python2.7/site-packages/django/contrib/auth/templates/gis/admin/google.html
 (Source does not exist)
django.template.loaders.app_directories.Loader: 
***/lib/python2.7/site-packages/django/forms/templates/gis/admin/google.html 
(Source does not exist)
django.template.loaders.app_directories.Loader: 
***/lib/python2.7/site-packages/filebrowser/templates/gis/admin/google.html 
(Source does not exist)
django.template.loaders.app_directories.Loader: 
***/lib/python2.7/site-packages/django/contrib/admin/templates/gis/admin/google.html
 (Source does not exist)
django.template.loaders.app_directories.Loader: 
***/lib/python2.7/site-packages/django/contrib/gis/templates/gis/admin/google.html
 (Source does not exist)
django.template.loaders.app_directories.Loader: 
***/lib/python2.7/site-packages/tinymce/templates/gis/admin/google.html (Source 
does not exist)
django.template.loaders.app_directories.Loader: 
***/lib/python2.7/site-packages/ios_notifications/templates/gis/admin/google.html
 (Source does not exist)
django.template.loaders.app_directories.Loader: 
***/lib/python2.7/site-packages/adminsortable/templates/gis/admin/google.html 
(Source does not exist)
django.template.loaders.app_directories.Loader: 
***/lib/python2.7/site-packages/django_mptt_admin/templates/gis/admin/google.html
 (Source does not exist)

Any idea why it is not picking up, and is there any way to overwrite the map 
widget (or any other widgets for the matter)?

Thanks.

Regards,
Kok Hoor

-- 
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/91732821-D7CC-46FD-8047-B19A404682B4%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to override the functionality of values()

2017-06-09 Thread Mallik Sai
By writing a custom method in ActiveQuerySet manager
https://stackoverflow.com/questions/44368818/fetch-json-field-value-using-values-in-django

On Thursday, June 8, 2017 at 4:44:35 PM UTC+5:30, Mallik Sai wrote:
>
> I my models I have a JSON Field and I want to get a particular key value 
> from json field in using values().
> assume my JOSN Field data is like
>{'key1':value1,'key2':value2,'key3':value3}
>
> eg: MyModel.objects.values( "field1", "field2", "key1(which is present in 
> json field)" )
>
> Is there any way to get json field key value directly or how can I 
> override the functionality of values() method.
>

-- 
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/02b2c7e4-d519-4c33-aea8-30285dda9b40%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to override the functionality of values()

2017-06-08 Thread Mallik Sai
I my models I have a JSON Field and I want to get a particular key value 
from json field in using values().
assume my JOSN Field data is like
   {'key1':value1,'key2':value2,'key3':value3}

eg: MyModel.objects.values( "field1", "field2", "key1(which is present in 
json field)" )

Is there any way to get json field key value directly or how can I override 
the functionality of values() method.

-- 
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/4620ccf9-2945-4776-88f5-89c396d718dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Is it possible to cleanly override another app's URL namespace in Django 1.11?

2017-05-17 Thread Robert Rollins
I have a project where I want to override a subset of the URLs provided by 
one of the third-party apps I have installed. I did so months ago, and it 
works just fine. However, once I upgraded to Django 1.11, I started seeing 
this warning appear every time I do anything with manage.py:

?: (urls.W005) URL namespace 'wagtailusers_groups' isn't unique. You may 
not be able to reverse all URLs in this namespace

How do I get rid of this warning? Do I need to accomplish this namespace 
override in some alternate manner, so that Django doesn't complain about 
the namespace being duplicated?

-- 
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/b693f1dd-8a0c-4296-b592-885c5927aba1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Override base filter for model's queryset (Django 1.6)?

2017-01-15 Thread Melvyn Sopacua
Hi Derek,

On Sunday 15 January 2017 06:53:10 Derek wrote:

> You don't appear to have understood my question; and I did not see
> this particular use case covered in the docs (which is why I asked
> it). You also pointed me to the wrong version; in particular
> "QuerySet.as_manager()" is not method in 1.6.

Take a look at the DahlBookManager example: it filters all books by 
author Dahl and "limits what is displayed".
If you compare it to your code, then you see that the entire 
MyModelQuerySet class can be deleted and your 
MyModelManager.get_queryset() method turns into:

def get_queryset(self):
return super(MyModelManager, self).get_queryset().filter(
classification='general'
)

Delete method could become something like this:

def delete(self):
qs = super(MyModelManager, self).get_queryset().filter(
code__neq='protected'
)
return qs.delete()

I'm using a call to super() in delete, so we get access to all objects. 
Please read the part about the default manager and its dangers before 
making it the default manager.

Last, but certainly not least: if you *only* need this for the admin, 
then it's better to look at ModelAdmin's list_filter property and/or 
get_queryset method and the has_delete_permission method. For example:

class MyModelAdmin(admin.ModelAdmin):
model = MyModel
list_filter = ('classification',)

def has_delete_permission(self, req, obj):
if super(MyModelAdmin, self).has_delete_permission(req, obj):
if obj.code != 'protected' :
return True
return False

Note that this doesn't set the default filter to 'general', but it does 
make filtering transparent (and allows access to objects which are not 
'general').

P.S.: The reason I pointed to 1.10 docs is simple: 1.6 is no longer 
supported by the Django Project and it's documentation has been removed 
from the site.

-- 
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/11651873.cjmEqRYSjg%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: Override base filter for model's queryset (Django 1.6)?

2017-01-15 Thread Derek
Hi Melvyn

You don't appear to have understood my question; and I did not see this 
particular use case covered in the docs (which is why I asked it). You also 
pointed me to the wrong version; in particular "QuerySet.as_manager()" is 
not method in 1.6.

On Saturday, 14 January 2017 21:58:15 UTC+2, Melvyn Sopacua wrote:
>
> On Saturday 14 January 2017 21:20:32 Derek wrote:
>
> > and I also want to override the base filter for
>
> > the model's
>
> > queryset to limit what is displayed.
>
>  
>
> This is covered in the Manager documentation 
> <https://docs.djangoproject.com/en/1.10/topics/db/managers/#modifying-a-manager-s-initial-queryset>
>  
> in detail.
>
>  
>
> -- 
>
> 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/51f720b2-965a-4b7b-b985-2e3e18703b2f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Override base filter for model's queryset (Django 1.6)?

2017-01-14 Thread Melvyn Sopacua
On Saturday 14 January 2017 21:20:32 Derek wrote:
> and I also want to override the base filter for
> the model's
> queryset to limit what is displayed.

This is covered in the Manager documentation[1] in detail.

-- 
Melvyn Sopacua


[1] 
https://docs.djangoproject.com/en/1.10/topics/db/managers/#modifyi
ng-a-manager-s-initial-queryset

-- 
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/4087984.zLPtikbxGM%40devstation.
For more options, visit https://groups.google.com/d/optout.


Override base filter for model's queryset (Django 1.6)?

2017-01-14 Thread Derek
I am looking for help with a Django 1.6 application.

The use case is not too complicated; I need to override the delete method
for
the queryset to prevent some records being removed by the bulk delete (run
via
the admin interface); and I also want to override the base filter for the
model's
queryset to limit what is displayed.

Preventing the deletion works well; but I cannot see how to override the
base
filter for the model - below are some examples of code I have tried that do
not
work.

I am sure this is not hard, but I cannot find the correct syntax.

Any ideas appreciated.

Thanks
Derek


```
from django.db.models import Model, Manager
from django.db.models import AutoField, CharField
from django.db.models.query import QuerySet


class MyModelQuerySet(QuerySet):

# NEED to override the base filter for this model ???

"""
def __init__(self, *args, **kwargs):
super(MyModelQuerySet, self).__init__(*args, **kwargs)
# does not filter at all?
self.queryset = models.Site.objects.filter(
classification='general')

def filter(self):
# just gives errors!
return self.queryset.filter(classification='special')
"""

def delete(self, *args, **kwargs):
for obj in self:
if obj.code != 'protected':
obj.delete()


class MyModelManager(Manager):

def get_queryset(self):
return MyModelQuerySet(model=self.model, using=self._db)


class MyModel(Model):
id = AutoField(primary_key=True)
name = CharField(
unique=True,
max_length=50,)
code = CharField(
unique=True,
max_length=250)
classification = CharField(
max_length=100)
objects = MyModelManager()
```

-- 
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/CAF1Wu3Mfo08k17rZvbAk3Nvv_nuSvr_SOD%3DSX%2B5JJaEqKyWu5Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Override save method to add list in the many to many field

2017-01-04 Thread Robin Lery
I have this model to save post from the users:

class Tag(models.Model):
name = models.CharField(max_length=255, unique=True)

def add_tags(obj_id, body):
object = Post.objects.get(id=obj_id)
tag_list = [Tag.objects.create(name=word) for word in body.split()]
for tag in tag_list:
object.tags.add(tag)

class Post(models.Model):
user = models.ForeignKey(User)
body = models.TextField()
tags = models.ManyToManyField(Tag, blank=True)
pub_date = models.DateTimeField(default=timezone.now)
activity = GenericRelation(Activity, related_query_name="posts")

def save(self, *args, **kwargs):
super(Post, self).save(*args, **kwargs)
if self.body:
body = self.body
obj_id = self.id
add_tags(obj_id, body)

So whenever a user post something, I would like to check if there's any
hash-tag used inside the body. If there are tags, then fetch the tags
inside the list.

But when I am posting, the tag objects are created, but they are not adding
for the Post.tags fields.

post.body example = Check #from the http://somesitedotcom/page#idtop #hell
yeah!

What am I doing wrong here?

-- 
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%2B4-nGrj%3DoK2Vmj7%2BqiDMJie8rQGFbQsjbbDAmj3vKrLGYx5qA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Override default fields in ModelForm

2016-03-21 Thread Ham Kibz
Here is the link to the 
question 
http://stackoverflow.com/questions/36124194/how-do-i-override-a-modelform-fields-attribute?noredirect=1#comment59888797_36124194


-- 
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/e82584d2-eae9-44a5-b926-d69c4b2296a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do I override the default admin page permissions?

2016-01-22 Thread Jonty Needham
Currently I want to allow certain users access to a certain administrator
page to allow or deny access for other users for a part of the tool.


I have overridden has_permission to grant access, however it says that "You
don't have permission to edit anything".

I've since tried overriding has_add/delete/change_permission in the
model_admin to true. but that's not helped the issue.

Anyone know how to do this?

I'd rather not create another group.

-- 
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/CANOQRbxjEew63KLwsy783ezXdNZE4tEFsC2y02_LM_9KrhiZ1g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


override django object action change_form.html

2016-01-19 Thread 张超
I want to override the change_from.html included in the directory 
django_object_actions/templates/django_object_actions/  ...I copy the  
change_from.html and put it in my app directory- 
myapp/templates/admin/django_object_actions/ ,but it can't work! 

-- 
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/2b9d5625-a6b4-431c-8de8-081f8042c757%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django model proxy override save

2015-11-18 Thread drifter
I want to override the save for a model when saved from the proxy I've 
tried commenting out as much as I can but it's still using the model save. 
Here's my code.

class MovieProxy(Movie):
class Meta:
verbose_name = 'movie show'
proxy=True

def save(self, *args, **kwargs):
#super(MovieProxy, self).save(*args, **kwargs)
fily = open('post-{0}'.format(self.id),'w')
fily.write(*args)
fily.write('\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n')
fily.write(**kwargs)
fily.close()

-- 
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/da0cdf2f-fab0-4c35-ba7d-1748c4ab48e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to override satchmo/apps/satchmo_store/contact/forms.py

2015-01-11 Thread RLF_UNIQUE
Whoops that didn't work

└── store
├── __pycache__
├── localsite
├── static
│   ├── admin
│   ├── cache
│   ├── css
│   ├── fonts
│   ├── images
│   └── js
└── templates
├── contact
├── product
└── shop

-- 
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/7904a0e2-30e3-4422-b594-5c70ee631f7d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to override satchmo/apps/satchmo_store/contact/forms.py

2015-01-11 Thread RLF_UNIQUE
└── store
├── __pycache__
├── contact
├── localsite
│   └── contact
├── static
│   ├── admin
│   ├── cache
│   ├── css
│   ├── fonts
│   ├── images
│   └── js
└── templates
├── contact
├── product
└── shop

-- 
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/2c879be1-bdfa-4a27-b8b0-9160f7b8fe29%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to override satchmo/apps/satchmo_store/contact/forms.py

2015-01-11 Thread RLF_UNIQUE
Can't figure out how to override this file, here is my directory structure

└── store ├── __pycache__ ├── localsite │   └── contact ├── static │   ├── 
admin │   │   ├── css │   │   ├── img │   │   │   └── gis │   │   └── js 
│   │   └── admin │   ├── cache
│   ├── css │   ├── fonts │   ├── images │   └── js └── templates ├── 
contact ├── product └── shop ├── checkout ├── email └── pdf

-- 
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/b40e26f7-3984-4523-8250-2e3fde7eb15b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Override Django Mptt Admin Queryset

2014-11-18 Thread Neeraj Sharma
Hi,

I want to override django mptt admin queryset, i want to filter the the 
queryset.
I also tried the following method in admin.py  but its not working.


def queryset(self, request):
qs = super(DataField_NEWAdmin, self).queryset(request) 
return qs.filter(game_event__id=10)

-- 
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/db59631b-9889-4cc6-8ccc-074d05da07fa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


override django mptt admin querset

2014-11-18 Thread Neeraj Sharma
Hi,

I want to override django mptt admin queryset, i want to filter the the 
queryset.
I also tried the following method in admin.py  but its not working.


def queryset(self, request):   

qs = super(DataField_NEWAdmin, self).queryset(request) 
qs.filter(game_event__id=request.GET.get("game_event__id"))



-- 
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/0ee64a3d-6653-492f-95e7-be526094b4ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Override

2014-11-02 Thread Collin Anderson
Hi Julien,

It also might be possible to "monkeypatch" the function. It's generally not 
recommended, but it might be worth it in your case.

Collin

-- 
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/5d1e09e0-386b-4c8d-8f40-5db7955bfdda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Override

2014-10-30 Thread Avraham Serour
this is why VCS were created for.
if the project is already under git, just clone and don't push

On Thu, Oct 30, 2014 at 6:09 AM, Julien Romagnoli <
julien.romagn...@gmail.com> wrote:

> Hello Guys,
>
> I'm working on the an existing project with django,
> but i need to change some behavior of this project for personal use.
>
> but the problem is if i change some part of code of the project after it
> will be complicate to apply the next update with git
>
> that why i'm trying to find a way for override some function, but without
> change the original code
>
> Best Regards
>
> --
> 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/fbef1cb5-1528-4279-88aa-8fb014fcd1ab%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/fbef1cb5-1528-4279-88aa-8fb014fcd1ab%40googlegroups.com?utm_medium=email_source=footer>
> .
> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFWa6tJmNZqjw%2BHvL9f5S9tVWWB7LYd5hEayaNn73e9xgqXYCw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Override

2014-10-30 Thread Julien Romagnoli
Hello Guys,

I'm working on the an existing project with django, 
but i need to change some behavior of this project for personal use.

but the problem is if i change some part of code of the project after it 
will be complicate to apply the next update with git

that why i'm trying to find a way for override some function, but without 
change the original code 

Best Regards

-- 
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/fbef1cb5-1528-4279-88aa-8fb014fcd1ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Override runserver django 1.7

2014-10-06 Thread Collin Anderson
It's because the staticfiles app is already overriding the built in 
runserver command, and it's competing with your app. I think it's the only 
case of a contrib app overriding a built-in command.

The migrate command is built-in to django and there are no contrib apps 
that override it.

-- 
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/781750ae-69d2-42ef-b2f5-8e0b394c9812%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Override runserver django 1.7

2014-10-06 Thread Carlos Perche
great, now it is working.

but i have still a question, why the position in the installed_apps does 
not affect the migrate command and affect the runserver command ?

thanks

-- 
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/0bea7e46-c84f-4404-8195-59f65a7be84a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Override runserver django 1.7

2014-10-06 Thread Collin Anderson
try putting the staticfiles app below saas in your INSTALLED_APPS

-- 
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/e690048c-8f14-4bea-8182-e5a617de1161%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Override runserver django 1.7

2014-10-06 Thread Carlos Perche
Hello, why not is possible override the command runserver.py in my custom 
app in Django 1.7, like this

# encoding: utf-8
from django.conf import settings
from django.core.management.base import CommandError, BaseCommand
# from django.contrib.staticfiles.management.commands.runserver import 
Command as RunserverCommand
from django.core.management.commands.runserver import Command as 
RunserverCommand

class Command(RunserverCommand):

def handle(self, addrport='', *args, **options):
database = options.get('database', 'default')
if (settings.DATABASES[database]['ENGINE'] == 
'saas.backends.postgresql_psycopg2' or
RunserverCommand is BaseCommand):
raise CommandError("migrate has been disabled, for database 
'{}'. Use migrate_schemas "
   "instead. Please read the documentation if 
you don't know why you "
   "shouldn't call migrate 
directly!".format(database))

super(Command, self).handle(self, addrport='', *args, **options)

def check_migrations(self):
"""
Checks to see if the set of migrations on disk matches the
migrations in the database. Prints a warning if they don't match.
"""
print('OK')

The output when i run manage.py, note that the runserver is not present in 
[saas] commands

Available subcommands:

[auth]
  ..
[debug_toolbar]
..

[django]
  ..

[reversion]
...
*[saas]*
*migrate*
*migrate_saas*
*migrate_schemas*
*sync_schemas*
*syncdb*
*tenant_command*

[sessions]
..

*[staticfiles]*
*collectstatic*
*findstatic*
*runserver*

-- 
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/6d16ea0e-accc-4c3a-81cd-2e98ccf24fc2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to override admin field widget?

2014-04-11 Thread Mark Phillips
Athat makes sense.

I was able to change the size of the text box in the widget file this way...

forms.TextInput(attrs={'size':'5'}),

Thanks again for all your help!! I learned a lot!

Mark


On Fri, Apr 11, 2014 at 9:03 AM, Lucas Klassmann
<lucasklassm...@gmail.com>wrote:

> Hi Mark,
>
> You must understand that each Widget in :
>
> widgets = (
> forms.TextInput(attrs=attrs),
> forms.TextInput(attrs=attrs),
> forms.TextInput(attrs=attrs),
> )
>
> Has a *render()* method that return html of widget. You must only
> concatenate each html of widget. You can use *format_output* like this:
>
> def format_output(self, rendered_widgets):
> widget_a = rendered_widgets[0]
> widget_b = rendered_widgets[1]
> widget_c = rendered_widgets[2]
>
> return "%s %s/%s" $(widget_a, widget_b, widget_c)
>
> I hope that solution above be that you want, but if you want customizing
> html/css/javascript of TextInput widget, you must override render() method
> of forms.TextInput widget.
>
> Cheers.
>
>
> On Fri, Apr 11, 2014 at 12:33 PM, Mark Phillips <
> m...@phillipsmarketing.biz> wrote:
>
>> Man, are you good;)
>>
>> It now works as expected!
>>
>> One last questionthe form shows three text boxes next to each other.
>> How can I change the html to look like this:
>>
>> [ ]  [ ] / []
>>
>> {text_box} space {text_box} / {text_box}
>>
>> It has something to do with format_output, but I don't understand how to
>> return a string to represent this layout. Also, how to control the size of
>> the text boxes.
>>
>> Thanks again!!
>>
>> Mark
>>
>>
>> On Fri, Apr 11, 2014 at 8:05 AM, Lucas Klassmann <
>> lucasklassm...@gmail.com> wrote:
>>
>>> Hi Mark,
>>>
>>> Because *TextInput *is a classe inside *forms *module and python is
>>> *case-sensitive*, try this:
>>>
>>> * forms.TextInput(attrs=attrs)*
>>>
>>> Cheers.
>>>
>>>
>>> On Fri, Apr 11, 2014 at 11:59 AM, Mark Phillips <
>>> m...@phillipsmarketing.biz> wrote:
>>>
>>>> Lucas,
>>>>
>>>> Thanks for your comment.
>>>>
>>>> I tried your suggestion, and got this error
>>>>
>>>> 'module' object has no attribute 'textInput'
>>>>
>>>> referring to the forms.textInput(attrs=attrs) in the widget class.
>>>>
>>>> I am only trying to replace three out of 16 fields in my Inventory
>>>> model with the custom widgets. I think your solution would require me to
>>>> enumerate all the other fields as well? I found this on the Internet -
>>>> http://collingrady.wordpress.com/2008/07/24/useful-form-tricks-in-django/,
>>>> which gave me the idea for how I wrote the form.
>>>>
>>>> I could be totally off base, so this is a great learning experience for
>>>> me! Thanks for your help!
>>>>
>>>> Mark
>>>>
>>>>
>>>>  On Fri, Apr 11, 2014 at 7:37 AM, Lucas Klassmann <
>>>> lucasklassm...@gmail.com> wrote:
>>>>
>>>>>  Hi!
>>>>>
>>>>> I will test you code, but for now, try rewrite the form class, this
>>>>> way:
>>>>>
>>>>> class MeasurementForm(forms.ModelForm):
>>>>> width = forms.DecimalField(widget=MeasurementWidget())
>>>>> height = forms.DecimalField(widget=MeasurementWidget())
>>>>> length = forms.DecimalField(widget=MeasurementWidget())
>>>>>
>>>>> class Meta:
>>>>> model = Inventory
>>>>>
>>>>> Cheers.
>>>>>
>>>>>
>>>>> On Fri, Apr 11, 2014 at 11:25 AM, Mark Phillips <
>>>>> m...@phillipsmarketing.biz> wrote:
>>>>>
>>>>>> I looked at the MultiWidget and tried to implement following a couple
>>>>>> of examples, but I have run into a problem. I get this error when I try 
>>>>>> to
>>>>>> open the admin form - type object 'MeasurementWidget' has no
>>>>>> attribute 'attrs'
>>>>>>
>>>>>> widgets.py
>>>>>> class MeasurementWidget(forms.MultiWidget):
>>>>>> def __init__(self, attrs=None):
>>>>>> widgets = (
>>>>>>

Re: How to override admin field widget?

2014-04-11 Thread Lucas Klassmann
Hi Mark,

You must understand that each Widget in :

widgets = (
forms.TextInput(attrs=attrs),
forms.TextInput(attrs=attrs),
forms.TextInput(attrs=attrs),
)

Has a *render()* method that return html of widget. You must only
concatenate each html of widget. You can use *format_output* like this:

def format_output(self, rendered_widgets):
widget_a = rendered_widgets[0]
widget_b = rendered_widgets[1]
widget_c = rendered_widgets[2]

return "%s %s/%s" $(widget_a, widget_b, widget_c)

I hope that solution above be that you want, but if you want customizing
html/css/javascript of TextInput widget, you must override render() method
of forms.TextInput widget.

Cheers.


On Fri, Apr 11, 2014 at 12:33 PM, Mark Phillips
<m...@phillipsmarketing.biz>wrote:

> Man, are you good;)
>
> It now works as expected!
>
> One last questionthe form shows three text boxes next to each other.
> How can I change the html to look like this:
>
> [ ]  [ ] / []
>
> {text_box} space {text_box} / {text_box}
>
> It has something to do with format_output, but I don't understand how to
> return a string to represent this layout. Also, how to control the size of
> the text boxes.
>
> Thanks again!!
>
> Mark
>
>
> On Fri, Apr 11, 2014 at 8:05 AM, Lucas Klassmann <lucasklassm...@gmail.com
> > wrote:
>
>> Hi Mark,
>>
>> Because *TextInput *is a classe inside *forms *module and python is
>> *case-sensitive*, try this:
>>
>> * forms.TextInput(attrs=attrs)*
>>
>> Cheers.
>>
>>
>> On Fri, Apr 11, 2014 at 11:59 AM, Mark Phillips <
>> m...@phillipsmarketing.biz> wrote:
>>
>>> Lucas,
>>>
>>> Thanks for your comment.
>>>
>>> I tried your suggestion, and got this error
>>>
>>> 'module' object has no attribute 'textInput'
>>>
>>> referring to the forms.textInput(attrs=attrs) in the widget class.
>>>
>>> I am only trying to replace three out of 16 fields in my Inventory model
>>> with the custom widgets. I think your solution would require me to
>>> enumerate all the other fields as well? I found this on the Internet -
>>> http://collingrady.wordpress.com/2008/07/24/useful-form-tricks-in-django/,
>>> which gave me the idea for how I wrote the form.
>>>
>>> I could be totally off base, so this is a great learning experience for
>>> me! Thanks for your help!
>>>
>>> Mark
>>>
>>>
>>>  On Fri, Apr 11, 2014 at 7:37 AM, Lucas Klassmann <
>>> lucasklassm...@gmail.com> wrote:
>>>
>>>>  Hi!
>>>>
>>>> I will test you code, but for now, try rewrite the form class, this way:
>>>>
>>>> class MeasurementForm(forms.ModelForm):
>>>> width = forms.DecimalField(widget=MeasurementWidget())
>>>> height = forms.DecimalField(widget=MeasurementWidget())
>>>> length = forms.DecimalField(widget=MeasurementWidget())
>>>>
>>>> class Meta:
>>>> model = Inventory
>>>>
>>>> Cheers.
>>>>
>>>>
>>>> On Fri, Apr 11, 2014 at 11:25 AM, Mark Phillips <
>>>> m...@phillipsmarketing.biz> wrote:
>>>>
>>>>> I looked at the MultiWidget and tried to implement following a couple
>>>>> of examples, but I have run into a problem. I get this error when I try to
>>>>> open the admin form - type object 'MeasurementWidget' has no
>>>>> attribute 'attrs'
>>>>>
>>>>> widgets.py
>>>>> class MeasurementWidget(forms.MultiWidget):
>>>>> def __init__(self, attrs=None):
>>>>> widgets = (
>>>>> forms.textInput(attrs=attrs),
>>>>> forms.textInput(attrs=attrs),
>>>>> forms.textInput(attrs=attrs),
>>>>> )
>>>>> super(MeasurementWidget, self).__init__(widgets, attrs)
>>>>>
>>>>> def decompress(self, value):
>>>>> if value:
>>>>> frac = Fraction(value)
>>>>> num = frac.numerator
>>>>> denom = frac.denominator
>>>>> whole = num/denom
>>>>> if whole == 0:
>>>>> whole = ''
>>>>> numerator = num - (num/denom)*denom
>>>>> return [whole,

Re: How to override admin field widget?

2014-04-11 Thread Mark Phillips
>> category = models.ForeignKey(Category)
>>>> length = models.DecimalField(max_digits=5, decimal_places=3,
>>>> default=0)
>>>> width = models.DecimalField(max_digits=5, decimal_places=3,
>>>> default=0)
>>>> height = models.DecimalField(max_digits=5, decimal_places=3,
>>>> default=0)
>>>> and other fields.
>>>>
>>>> admin.py
>>>> class MeasurementForm(forms.ModelForm):
>>>> def __init__(self, *args, **kwargs):
>>>> super(MeasurementForm, self).__init__(*args, **kwargs)
>>>> self.fields['width'].widget = MeasurementWidget
>>>> self.fields['height'].widget = MeasurementWidget
>>>> self.fields['length'].widget = MeasurementWidget
>>>>
>>>> class Meta:
>>>> model = Inventory
>>>>
>>>> class InventoryAdmin(admin.ModelAdmin):
>>>> list_display = ('id','location', 'room', 'category', 'description',
>>>> 'condition', 'length', 'width', 'height', 'status', 'sale_price',
>>>> 'selling_costs', 'debt')
>>>> list_filter = ['category']
>>>> search_fields = ['description']
>>>> form = MeasurementForm
>>>> inlines = [NoteInline, ImageInline, EstimateInline]
>>>>
>>>> admin.site.register(Inventory, InventoryAdmin)
>>>>
>>>> I am really lost here. Does anyone have an easier way to override the
>>>> widgets on the admin form?
>>>>
>>>> Thanks,
>>>>
>>>> Mark
>>>>
>>>>
>>>> On Thu, Apr 10, 2014 at 7:09 PM, Lucas Klassmann <
>>>> lucasklassm...@gmail.com> wrote:
>>>>
>>>>> Hi!
>>>>>
>>>>> I never used this, but i found here and can be useful:
>>>>>
>>>>>
>>>>> https://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.MultiWidget
>>>>>
>>>>> Cheers.
>>>>>
>>>>>
>>>>> On Thu, Apr 10, 2014 at 10:56 PM, Mark Phillips <
>>>>> m...@phillipsmarketing.biz> wrote:
>>>>>
>>>>>> I hope I am using the right terminology
>>>>>>
>>>>>> I have a Decimal field in a model called 'width'. In the admin
>>>>>> screen, I would like to display this field as three text boxes like this:
>>>>>>
>>>>>> width:  [] []/[]
>>>>>>
>>>>>> so I can enter 2 1/8 for the width, and then have the code convert
>>>>>> that to 2.125 as a Decimal field and store that Decimal field in the
>>>>>> database.
>>>>>>
>>>>>> How would I go about doing this?
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> Mark
>>>>>>
>>>>>> --
>>>>>> 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/CAEqej2MkiPYfjO4afqyWVr587AL5UczhuzJCLhgxeqjda8%2BcDw%40mail.gmail.com<https://groups.google.com/d/msgid/django-users/CAEqej2MkiPYfjO4afqyWVr587AL5UczhuzJCLhgxeqjda8%2BcDw%40mail.gmail.com?utm_medium=email_source=footer>
>>>>>> .
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Lucas Klassmann
>>>>> Desenvolvedor de Software
>>>>>
>>>>> Email: lucasklassm...@gmail.com
>>>>> Web site: http://www.lucasklassmann.com
>>>>>
>>>>> --
>>>>> 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...@goog

Re: How to override admin field widget?

2014-04-11 Thread Lucas Klassmann
Hi Mark,

Because *TextInput *is a classe inside *forms *module and python is
*case-sensitive*, try this:

* forms.TextInput(attrs=attrs)*

Cheers.


On Fri, Apr 11, 2014 at 11:59 AM, Mark Phillips
<m...@phillipsmarketing.biz>wrote:

> Lucas,
>
> Thanks for your comment.
>
> I tried your suggestion, and got this error
>
> 'module' object has no attribute 'textInput'
>
> referring to the forms.textInput(attrs=attrs) in the widget class.
>
> I am only trying to replace three out of 16 fields in my Inventory model
> with the custom widgets. I think your solution would require me to
> enumerate all the other fields as well? I found this on the Internet -
> http://collingrady.wordpress.com/2008/07/24/useful-form-tricks-in-django/,
> which gave me the idea for how I wrote the form.
>
> I could be totally off base, so this is a great learning experience for
> me! Thanks for your help!
>
> Mark
>
>
>  On Fri, Apr 11, 2014 at 7:37 AM, Lucas Klassmann <
> lucasklassm...@gmail.com> wrote:
>
>>  Hi!
>>
>> I will test you code, but for now, try rewrite the form class, this way:
>>
>> class MeasurementForm(forms.ModelForm):
>> width = forms.DecimalField(widget=MeasurementWidget())
>> height = forms.DecimalField(widget=MeasurementWidget())
>> length = forms.DecimalField(widget=MeasurementWidget())
>>
>> class Meta:
>> model = Inventory
>>
>> Cheers.
>>
>>
>> On Fri, Apr 11, 2014 at 11:25 AM, Mark Phillips <
>> m...@phillipsmarketing.biz> wrote:
>>
>>> I looked at the MultiWidget and tried to implement following a couple of
>>> examples, but I have run into a problem. I get this error when I try to
>>> open the admin form - type object 'MeasurementWidget' has no attribute
>>> 'attrs'
>>>
>>> widgets.py
>>> class MeasurementWidget(forms.MultiWidget):
>>> def __init__(self, attrs=None):
>>> widgets = (
>>> forms.textInput(attrs=attrs),
>>> forms.textInput(attrs=attrs),
>>> forms.textInput(attrs=attrs),
>>> )
>>> super(MeasurementWidget, self).__init__(widgets, attrs)
>>>
>>> def decompress(self, value):
>>> if value:
>>> frac = Fraction(value)
>>> num = frac.numerator
>>> denom = frac.denominator
>>> whole = num/denom
>>> if whole == 0:
>>> whole = ''
>>> numerator = num - (num/denom)*denom
>>> return [whole, numerator, denom]
>>> return ['', '', '']
>>>
>>> def format_output(self, rendered_widgets):
>>> return u''.join(rendered_widgets)
>>>
>>> def value_from_datadict(self, data, files, name):
>>> valuelist = [widget.value_from_datadict(data, files, name +
>>> '_%s' % i) for i, widget in enumerate(self.widgets)]
>>> try:
>>> if valuelist[0] == '':
>>> valuelist[0] = 0
>>> numerator = int(valuelist[0]) * int(valuelist[2]) +
>>> int(valuelist[1])
>>> denominator = int(valuelist[2])
>>> return Decimal(float(Fraction(numerator, denominator)))
>>> except ValueError:
>>> return ""
>>>
>>> models.py
>>> class Inventory(models.Model):
>>> location = models.ForeignKey(Location)
>>> room = models.ForeignKey(Room, blank=True, null=True)
>>> condition = models.ForeignKey(Condition)
>>> status = models.ForeignKey(Status)
>>> category = models.ForeignKey(Category)
>>> length = models.DecimalField(max_digits=5, decimal_places=3,
>>> default=0)
>>> width = models.DecimalField(max_digits=5, decimal_places=3,
>>> default=0)
>>> height = models.DecimalField(max_digits=5, decimal_places=3,
>>> default=0)
>>> and other fields.
>>>
>>> admin.py
>>> class MeasurementForm(forms.ModelForm):
>>> def __init__(self, *args, **kwargs):
>>> super(MeasurementForm, self).__init__(*args, **kwargs)
>>> self.fields['width'].widget = MeasurementWidget
>>> self.fields['height'].widget = MeasurementWidget
>>> self.fields['length'].widget = MeasurementWidget
>>>
>>> class Meta:
>>> model = Inventory
>>>
>>> class I

Re: How to override admin field widget?

2014-04-11 Thread Mark Phillips
Lucas,

Thanks for your comment.

I tried your suggestion, and got this error

'module' object has no attribute 'textInput'

referring to the forms.textInput(attrs=attrs) in the widget class.

I am only trying to replace three out of 16 fields in my Inventory model
with the custom widgets. I think your solution would require me to
enumerate all the other fields as well? I found this on the Internet -
http://collingrady.wordpress.com/2008/07/24/useful-form-tricks-in-django/,
which gave me the idea for how I wrote the form.

I could be totally off base, so this is a great learning experience for me!
Thanks for your help!

Mark


On Fri, Apr 11, 2014 at 7:37 AM, Lucas Klassmann
<lucasklassm...@gmail.com>wrote:

> Hi!
>
> I will test you code, but for now, try rewrite the form class, this way:
>
> class MeasurementForm(forms.ModelForm):
> width = forms.DecimalField(widget=MeasurementWidget())
> height = forms.DecimalField(widget=MeasurementWidget())
> length = forms.DecimalField(widget=MeasurementWidget())
>
> class Meta:
> model = Inventory
>
> Cheers.
>
>
> On Fri, Apr 11, 2014 at 11:25 AM, Mark Phillips <
> m...@phillipsmarketing.biz> wrote:
>
>> I looked at the MultiWidget and tried to implement following a couple of
>> examples, but I have run into a problem. I get this error when I try to
>> open the admin form - type object 'MeasurementWidget' has no attribute
>> 'attrs'
>>
>> widgets.py
>> class MeasurementWidget(forms.MultiWidget):
>> def __init__(self, attrs=None):
>> widgets = (
>> forms.textInput(attrs=attrs),
>> forms.textInput(attrs=attrs),
>> forms.textInput(attrs=attrs),
>> )
>> super(MeasurementWidget, self).__init__(widgets, attrs)
>>
>> def decompress(self, value):
>> if value:
>> frac = Fraction(value)
>> num = frac.numerator
>> denom = frac.denominator
>> whole = num/denom
>> if whole == 0:
>> whole = ''
>> numerator = num - (num/denom)*denom
>> return [whole, numerator, denom]
>> return ['', '', '']
>>
>> def format_output(self, rendered_widgets):
>> return u''.join(rendered_widgets)
>>
>> def value_from_datadict(self, data, files, name):
>> valuelist = [widget.value_from_datadict(data, files, name + '_%s'
>> % i) for i, widget in enumerate(self.widgets)]
>> try:
>> if valuelist[0] == '':
>> valuelist[0] = 0
>> numerator = int(valuelist[0]) * int(valuelist[2]) +
>> int(valuelist[1])
>> denominator = int(valuelist[2])
>> return Decimal(float(Fraction(numerator, denominator)))
>> except ValueError:
>> return ""
>>
>> models.py
>> class Inventory(models.Model):
>> location = models.ForeignKey(Location)
>> room = models.ForeignKey(Room, blank=True, null=True)
>> condition = models.ForeignKey(Condition)
>> status = models.ForeignKey(Status)
>> category = models.ForeignKey(Category)
>> length = models.DecimalField(max_digits=5, decimal_places=3,
>> default=0)
>> width = models.DecimalField(max_digits=5, decimal_places=3, default=0)
>> height = models.DecimalField(max_digits=5, decimal_places=3,
>> default=0)
>> and other fields.
>>
>> admin.py
>> class MeasurementForm(forms.ModelForm):
>> def __init__(self, *args, **kwargs):
>> super(MeasurementForm, self).__init__(*args, **kwargs)
>> self.fields['width'].widget = MeasurementWidget
>> self.fields['height'].widget = MeasurementWidget
>> self.fields['length'].widget = MeasurementWidget
>>
>> class Meta:
>> model = Inventory
>>
>> class InventoryAdmin(admin.ModelAdmin):
>> list_display = ('id','location', 'room', 'category', 'description',
>> 'condition', 'length', 'width', 'height', 'status', 'sale_price',
>> 'selling_costs', 'debt')
>> list_filter = ['category']
>> search_fields = ['description']
>> form = MeasurementForm
>> inlines = [NoteInline, ImageInline, EstimateInline]
>>
>> admin.site.register(Inventory, InventoryAdmin)
>>
>> I am really lost here. Does anyone have an easier way to override the
>> widgets on the admin form?
>>
>> Thanks,
>>
>> Mark
>>
>>
>> On Thu, Apr 10, 2014 at 7:09 PM, Lucas Klassmann <
>&

Re: How to override admin field widget?

2014-04-11 Thread Lucas Klassmann
Hi!

I will test you code, but for now, try rewrite the form class, this way:

class MeasurementForm(forms.ModelForm):
width = forms.DecimalField(widget=MeasurementWidget())
height = forms.DecimalField(widget=MeasurementWidget())
length = forms.DecimalField(widget=MeasurementWidget())

class Meta:
model = Inventory

Cheers.


On Fri, Apr 11, 2014 at 11:25 AM, Mark Phillips
<m...@phillipsmarketing.biz>wrote:

> I looked at the MultiWidget and tried to implement following a couple of
> examples, but I have run into a problem. I get this error when I try to
> open the admin form - type object 'MeasurementWidget' has no attribute
> 'attrs'
>
> widgets.py
> class MeasurementWidget(forms.MultiWidget):
> def __init__(self, attrs=None):
> widgets = (
> forms.textInput(attrs=attrs),
> forms.textInput(attrs=attrs),
> forms.textInput(attrs=attrs),
> )
> super(MeasurementWidget, self).__init__(widgets, attrs)
>
> def decompress(self, value):
> if value:
> frac = Fraction(value)
> num = frac.numerator
> denom = frac.denominator
> whole = num/denom
> if whole == 0:
> whole = ''
> numerator = num - (num/denom)*denom
> return [whole, numerator, denom]
> return ['', '', '']
>
> def format_output(self, rendered_widgets):
> return u''.join(rendered_widgets)
>
> def value_from_datadict(self, data, files, name):
> valuelist = [widget.value_from_datadict(data, files, name + '_%s'
> % i) for i, widget in enumerate(self.widgets)]
> try:
> if valuelist[0] == '':
> valuelist[0] = 0
> numerator = int(valuelist[0]) * int(valuelist[2]) +
> int(valuelist[1])
> denominator = int(valuelist[2])
> return Decimal(float(Fraction(numerator, denominator)))
> except ValueError:
> return ""
>
> models.py
> class Inventory(models.Model):
> location = models.ForeignKey(Location)
> room = models.ForeignKey(Room, blank=True, null=True)
> condition = models.ForeignKey(Condition)
> status = models.ForeignKey(Status)
> category = models.ForeignKey(Category)
> length = models.DecimalField(max_digits=5, decimal_places=3, default=0)
> width = models.DecimalField(max_digits=5, decimal_places=3, default=0)
> height = models.DecimalField(max_digits=5, decimal_places=3, default=0)
> and other fields.
>
> admin.py
> class MeasurementForm(forms.ModelForm):
> def __init__(self, *args, **kwargs):
> super(MeasurementForm, self).__init__(*args, **kwargs)
> self.fields['width'].widget = MeasurementWidget
> self.fields['height'].widget = MeasurementWidget
> self.fields['length'].widget = MeasurementWidget
>
> class Meta:
> model = Inventory
>
> class InventoryAdmin(admin.ModelAdmin):
> list_display = ('id','location', 'room', 'category', 'description',
> 'condition', 'length', 'width', 'height', 'status', 'sale_price',
> 'selling_costs', 'debt')
> list_filter = ['category']
> search_fields = ['description']
> form = MeasurementForm
> inlines = [NoteInline, ImageInline, EstimateInline]
>
> admin.site.register(Inventory, InventoryAdmin)
>
> I am really lost here. Does anyone have an easier way to override the
> widgets on the admin form?
>
> Thanks,
>
> Mark
>
>
> On Thu, Apr 10, 2014 at 7:09 PM, Lucas Klassmann <lucasklassm...@gmail.com
> > wrote:
>
>> Hi!
>>
>> I never used this, but i found here and can be useful:
>>
>>
>> https://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.MultiWidget
>>
>> Cheers.
>>
>>
>> On Thu, Apr 10, 2014 at 10:56 PM, Mark Phillips <
>> m...@phillipsmarketing.biz> wrote:
>>
>>> I hope I am using the right terminology
>>>
>>> I have a Decimal field in a model called 'width'. In the admin screen, I
>>> would like to display this field as three text boxes like this:
>>>
>>> width:  [] []/[]
>>>
>>> so I can enter 2 1/8 for the width, and then have the code convert that
>>> to 2.125 as a Decimal field and store that Decimal field in the database.
>>>
>>> How would I go about doing this?
>>>
>>> Thanks,
>>>
>>> Mark
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To uns

Re: How to override admin field widget?

2014-04-11 Thread Mark Phillips
I looked at the MultiWidget and tried to implement following a couple of
examples, but I have run into a problem. I get this error when I try to
open the admin form - type object 'MeasurementWidget' has no attribute
'attrs'

widgets.py
class MeasurementWidget(forms.MultiWidget):
def __init__(self, attrs=None):
widgets = (
forms.textInput(attrs=attrs),
forms.textInput(attrs=attrs),
forms.textInput(attrs=attrs),
)
super(MeasurementWidget, self).__init__(widgets, attrs)

def decompress(self, value):
if value:
frac = Fraction(value)
num = frac.numerator
denom = frac.denominator
whole = num/denom
if whole == 0:
whole = ''
numerator = num - (num/denom)*denom
return [whole, numerator, denom]
return ['', '', '']

def format_output(self, rendered_widgets):
return u''.join(rendered_widgets)

def value_from_datadict(self, data, files, name):
valuelist = [widget.value_from_datadict(data, files, name + '_%s' %
i) for i, widget in enumerate(self.widgets)]
try:
if valuelist[0] == '':
valuelist[0] = 0
numerator = int(valuelist[0]) * int(valuelist[2]) +
int(valuelist[1])
denominator = int(valuelist[2])
return Decimal(float(Fraction(numerator, denominator)))
except ValueError:
return ""

models.py
class Inventory(models.Model):
location = models.ForeignKey(Location)
room = models.ForeignKey(Room, blank=True, null=True)
condition = models.ForeignKey(Condition)
status = models.ForeignKey(Status)
category = models.ForeignKey(Category)
length = models.DecimalField(max_digits=5, decimal_places=3, default=0)
width = models.DecimalField(max_digits=5, decimal_places=3, default=0)
height = models.DecimalField(max_digits=5, decimal_places=3, default=0)
and other fields.

admin.py
class MeasurementForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(MeasurementForm, self).__init__(*args, **kwargs)
self.fields['width'].widget = MeasurementWidget
self.fields['height'].widget = MeasurementWidget
self.fields['length'].widget = MeasurementWidget

class Meta:
model = Inventory

class InventoryAdmin(admin.ModelAdmin):
list_display = ('id','location', 'room', 'category', 'description',
'condition', 'length', 'width', 'height', 'status', 'sale_price',
'selling_costs', 'debt')
list_filter = ['category']
search_fields = ['description']
form = MeasurementForm
inlines = [NoteInline, ImageInline, EstimateInline]

admin.site.register(Inventory, InventoryAdmin)

I am really lost here. Does anyone have an easier way to override the
widgets on the admin form?

Thanks,

Mark


On Thu, Apr 10, 2014 at 7:09 PM, Lucas Klassmann
<lucasklassm...@gmail.com>wrote:

> Hi!
>
> I never used this, but i found here and can be useful:
>
>
> https://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.MultiWidget
>
> Cheers.
>
>
> On Thu, Apr 10, 2014 at 10:56 PM, Mark Phillips <
> m...@phillipsmarketing.biz> wrote:
>
>> I hope I am using the right terminology
>>
>> I have a Decimal field in a model called 'width'. In the admin screen, I
>> would like to display this field as three text boxes like this:
>>
>> width:  [] []/[]
>>
>> so I can enter 2 1/8 for the width, and then have the code convert that
>> to 2.125 as a Decimal field and store that Decimal field in the database.
>>
>> How would I go about doing this?
>>
>> Thanks,
>>
>> Mark
>>
>> --
>> 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/CAEqej2MkiPYfjO4afqyWVr587AL5UczhuzJCLhgxeqjda8%2BcDw%40mail.gmail.com<https://groups.google.com/d/msgid/django-users/CAEqej2MkiPYfjO4afqyWVr587AL5UczhuzJCLhgxeqjda8%2BcDw%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Lucas Klassmann
> Desenvolvedor de Software
>
> Email: lucasklassm...@gmail.com
> Web site: http://www.lucasklassmann.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubsc

Re: How to override admin field widget?

2014-04-10 Thread Lucas Klassmann
Hi!

I never used this, but i found here and can be useful:

https://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.MultiWidget

Cheers.


On Thu, Apr 10, 2014 at 10:56 PM, Mark Phillips
wrote:

> I hope I am using the right terminology
>
> I have a Decimal field in a model called 'width'. In the admin screen, I
> would like to display this field as three text boxes like this:
>
> width:  [] []/[]
>
> so I can enter 2 1/8 for the width, and then have the code convert that to
> 2.125 as a Decimal field and store that Decimal field in the database.
>
> How would I go about doing this?
>
> Thanks,
>
> Mark
>
> --
> 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/CAEqej2MkiPYfjO4afqyWVr587AL5UczhuzJCLhgxeqjda8%2BcDw%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Lucas Klassmann
Desenvolvedor de Software

Email: lucasklassm...@gmail.com
Web site: http://www.lucasklassmann.com

-- 
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/CAOz50pLMMRv8-boG1C0Rb7vriVnpO-G953Lbh0zoRhjG6-zsLQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


How to override admin field widget?

2014-04-10 Thread Mark Phillips
I hope I am using the right terminology

I have a Decimal field in a model called 'width'. In the admin screen, I
would like to display this field as three text boxes like this:

width:  [] []/[]

so I can enter 2 1/8 for the width, and then have the code convert that to
2.125 as a Decimal field and store that Decimal field in the database.

How would I go about doing this?

Thanks,

Mark

-- 
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/CAEqej2MkiPYfjO4afqyWVr587AL5UczhuzJCLhgxeqjda8%2BcDw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Override grappelli js files

2014-02-25 Thread rush
Wow, that's a great explanation. Thank you, Felipa! wbr,rush.   26.02.2014, 00:52, "Felipe Bessa Coelho" <fcoelh...@gmail.com>:2014-02-25 17:18 GMT-03:00 rush <dja...@irush.su>:Hi,I'm using grappelli and I have two files in it I need to modify:admin/js/SelectBox.js
admin/js/SelectFilter2.jsI thought it would be a good idea to put it into my app static directory:my_app/static/admin/js/SelectBox.js
my_app/static/admin/js/SelectFilter2.jsBut whenever I try ./manage.py collectstatic files from my_app are overrided by original files from grappelli, however I need it vice versa.I need just to add several strings in this files into existing functions, so I can't handle it within a new js files and include into Media class ( from my point of view ).Is there any way to override grappelli files? When collecting static files, if there are multiple files with the same name Django will pick the first one it finds. [1] What that means is, unless you've changed STATICFILES_FINDERS, files inside folders in STATICFILES_DIRS will have the highest priority. And if static files inside apps are used, Django will follow the INSTALLED_APPS order, meaning you probably have grappelli _above_ my_app. If for whatever reason you don't want/can't change the order your apps appear in INSTALLED_APPS, you may consider placing those files in a folder using STATICFILES_DIRS.[1] https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-STATICFILES_FINDERS --  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/CAP5dYfP7pmXZsR592gx%2Bp%3DND1w9__Jq%3Dyzxnok2BFj5Gsi1rsw%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.



-- 
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/262611393363533%40web26h.yandex.ru.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Override grappelli js files

2014-02-25 Thread Felipe Bessa Coelho
2014-02-25 17:18 GMT-03:00 rush <dja...@irush.su>:

> Hi,
>
> I'm using grappelli and I have two files in it I need to modify:
>
> admin/js/SelectBox.js
> admin/js/SelectFilter2.js
>
> I thought it would be a good idea to put it into my app static directory:
>
> my_app/static/admin/js/SelectBox.js
> my_app/static/admin/js/SelectFilter2.js
>
> But whenever I try ./manage.py collectstatic files from my_app are
> overrided by original files from grappelli, however I need it vice versa.
>
> I need just to add several strings in this files into existing functions,
> so I can't handle it within a new js files and include into Media class (
> from my point of view ).
>
> Is there any way to override grappelli files?
>

When collecting static files, if there are multiple files with the same
name Django will pick the first one it finds. [1] What that means is,
unless you've changed STATICFILES_FINDERS, files inside folders in
STATICFILES_DIRS will have the highest priority. And if static files inside
apps are used, Django will follow the INSTALLED_APPS order, meaning you
probably have grappelli _above_ my_app.

If for whatever reason you don't want/can't change the order your apps
appear in INSTALLED_APPS, you may consider placing those files in a folder
using STATICFILES_DIRS.

[1]
https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-STATICFILES_FINDERS

-- 
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/CAP5dYfP7pmXZsR592gx%2Bp%3DND1w9__Jq%3Dyzxnok2BFj5Gsi1rsw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Override grappelli js files

2014-02-25 Thread rush
Hi,I'm using grappelli and I have two files in it I need to modify:admin/js/SelectBox.js
admin/js/SelectFilter2.jsI thought it would be a good idea to put it into my app static directory:my_app/static/admin/js/SelectBox.js
my_app/static/admin/js/SelectFilter2.jsBut whenever I try ./manage.py collectstatic files from my_app are overrided by original files from grappelli, however I need it vice versa.I need just to add several strings in this files into existing functions, so I can't handle it within a new js files and include into Media class ( from my point of view ).Is there any way to override grappelli files? wbr,rush.



-- 
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/383141393359498%40web3m.yandex.ru.
For more options, visit https://groups.google.com/groups/opt_out.


Re: proper way to override text plugin widget

2013-10-07 Thread Roberto López López
wrong list, sorry :-(


On 10/07/2013 11:23 AM, Roberto López López wrote:
> Hi,
>
> The users of my project prefer ckeditor, so I am wondering how to use it
> for cms.plugins.text . I am already making use of django-ckeditor in
> other parts of the application. Can anyone enlighten me please?
>
> Thanks,
>
> Roberto
>
>


-- 

Roberto López López
System Developer
Parallab, Uni Computing
+47 55584091

-- 
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/52527E23.2080102%40uni.no.
For more options, visit https://groups.google.com/groups/opt_out.


proper way to override text plugin widget

2013-10-07 Thread Roberto López López

Hi,

The users of my project prefer ckeditor, so I am wondering how to use it
for cms.plugins.text . I am already making use of django-ckeditor in
other parts of the application. Can anyone enlighten me please?

Thanks,

Roberto


-- 
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/52527D84.7020301%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Override model field attributes from a ModelForm?

2013-10-03 Thread Storn White
Hi,

My custom user model requires unique email addresses, which are the users' 
identifiers.

My user registration modelform works great.  If a user tries to register 
with an email that is already in the system, the form fails to validate and 
the 'unique' invalid message is displayed back to the user.

I am trying to create an authentication modelform based on the same user 
model.  When I try to authenticate a registered user, the email field 
throws the unique validation error.  How can I overwrite this property? 
 I've tried:

class MyUserModel(AbstractBaseUser):
"""
Custom User Model requires unique email address.
"""
# email field
email = models.EmailField(
unique=True,
error_messages={
'invalid': "You must enter a valid email address.",
'unique': "Your email address is already in our system!"
}
)

class MyAuthForm(forms.ModelForm):
"""
Form for authenticating users.
"""
def __init__(self, *args, **kwargs):
super(MyAuthForm, self).__init__(*args, **kwargs)
self.Meta.model.email.unique = True

I've tried a few variations on this with no luck.  Any ideas?

Thanks!
  

-- 
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/32f415a0-99e2-461b-8dca-44c0ea98ce93%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: xadmin override base_site.html

2013-09-30 Thread Christian Schulz
Ahh got it , different versions in my installation.

Christian


Am Montag, 30. September 2013 16:54:43 UTC+2 schrieb Christian Schulz:
>
> Hi,
>
> has someboday a clue why I get this error.
> Without the modifications xadmin works fine, but if  I copy  for 
> modifications in my ../templates/xadmin/base_site.html
> I got the error below.
>
> If I cut this *if step*  the template is loaded but without surprise in 
> fragile form. Has anybody an idea where this menu_template
> comes from , can't find it yet?  With the complete  template/xadmin folder 
> in my ../templatesthe problem is still the same.
>
> Thanks Christian
>
> TemplateDoesNotExist at /admin
> No exception supplied
> Request Method: GET
> Request URL: http://localhost:8000/admin
> Django Version: 1.5.4
> Exception Type: TemplateDoesNotExist
> Exception Location: 
> /home/chris/.local/lib/python2.7/site-packages/django/template/loader.py 
> in find_template, line 139
>
>
>
> 31  32  class="col-sm-1 col-md-2"> 33 {% block navbar %} 34 {% if nav_menu %} 35 {% 
> include menu_template %} 36 {% else %} 37 {% trans "You don't have 
> permission to edit anything." %} 38 {% endif %} 39 {% endblock %} 40
>
>
>

-- 
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/fe62b230-1071-4ee6-a15b-67720f4baf3f%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


xadmin override base_site.html

2013-09-30 Thread Christian Schulz
Hi,

has someboday a clue why I get this error.
Without the modifications xadmin works fine, but if  I copy  for 
modifications in my ../templates/xadmin/base_site.html
I got the error below.

If I cut this *if step*  the template is loaded but without surprise in 
fragile form. Has anybody an idea where this menu_template
comes from , can't find it yet?  With the complete  template/xadmin folder 
in my ../templatesthe problem is still the same.

Thanks Christian

TemplateDoesNotExist at /admin
No exception supplied
Request Method: GET
Request URL: http://localhost:8000/admin
Django Version: 1.5.4
Exception Type: TemplateDoesNotExist
Exception Location: 
/home/chris/.local/lib/python2.7/site-packages/django/template/loader.py 
in find_template, line 139



31  32  33 {% block navbar %} 34 {% if nav_menu %} 35 {% 
include menu_template %} 36 {% else %} 37 {% trans "You don't have 
permission to edit anything." %} 38 {% endif %} 39 {% endblock %} 40


-- 
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/5ca8f889-7d16-487c-9d92-ae9afc3db383%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Ordering the forms within a formset? (How to override __iter__())

2012-09-24 Thread Houmie
 

deals_formset_factory = modelformset_factory(Deal, form=DealCForm, extra=1, 
can_delete=True, max_num=5)   
deals_formset = deals_formset_factory(queryset=query)

Is there a way to say the one extra form shall always be the first form no 
matter how many more instance forms are within the deals_formset?

I found this bit in the 
documentation<https://docs.djangoproject.com/en/dev/topics/forms/formsets/#formsets>
:

Iterating over the formset will render the forms in the order they were 
created. You can change this order by providing an alternate implementation 
for the __iter__() method.

Formsets can also be indexed into, which returns the corresponding form. If 
you override __iter__, you will need to also override __getitem__ to have 
matching behavior.

As I am still a bit new to python/django, I don't know where to begin. Is 
there any short example how __iter__() and __getitem() override have to 
look like? 

many Thanks

-- 
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/-/2_mvgRg0R-AJ.
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: Override save or other options?

2012-09-12 Thread Cal Leeming [Simplicity Media Ltd]
Curious, we had to do a similar thing for billing periods on our VoIP
system a while back.

We ended up using dateutil, here's a bit of a code dump.

This was all triggered from populate_billing_periods() which was called at
the point of processing billing info (which happens every 24 hours)

Would strongly recommend looking at dateutil tho

=
def get_billing_periods(self, date):
return list(
rrule.rrule(
rrule.MONTHLY,
dtstart=self.effective_start_date,
until=date
)
)

def populate_billing_periods(self, *args, **kwargs):
# Now calculate all of our billing dates
_billing_dates = self._get_billing_date_range()

# this ensures we have all the correct billing periods
for billing_date in _billing_dates:
# create the billing period for this billing date
billing_period, created = DomainBillingPeriod.objects.get_or_create(
billing_date = billing_date,
domain = self
)
=

Apologies for the messy dump, hope it helps a little tho.

Cal

On Tue, Sep 11, 2012 at 5:23 AM, Lachlan Musicman  wrote:

> Hi All,
>
> Simplistically, I have an event type model (for a "school class") with
> a date field.
>
> On saving of the first event, I want to add recurring objects.
> Specifics for this project are "up to a latest date" (ie, end of term)
> and "recur weekly only" (not daily, monthly, yearly, etc - for the
> school's weekly timetable)
>
> I have just tried overriding the save method on the object to auto
> create these objects.
>
> def save(self):
>super(Event, self).save()
>
>last_date = self.term.end_date
>series_date = self.date + datetime.timedelta(7)
>while series_date < last_date:
>   super(Session, self).save(date = series_date)
>
> I've realised that this will most probably not make new objects, but
> will only update the date on the current object. Quite separately, I'm
> also getting keyword argument error on "date".
>
> How would you go about creating a series of events from a single save
> press? Should I be using some sort of external system (celery or ???)
> or should I write an additional method for the model that does the
> auto-creation?
>
> At some point after working this out, I will have a need to delete the
> series as well...and I don't even want to think about editing the
> series. Let's start with creating a recurring event and I'll work on
> that later.
>
> Cheers
> L.
>
>
>
>
> --
> ...we look at the present day through a rear-view mirror. This is
> something Marshall McLuhan said back in the Sixties, when the world
> was in the grip of authentic-seeming future narratives. He said, “We
> look at the present through a rear-view mirror. We march backwards
> into the future.”
>
> http://www.warrenellis.com/?p=14314
>
> --
> 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.
>
>

-- 
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: Override save or other options?

2012-09-11 Thread Lachlan Musicman
On Wed, Sep 12, 2012 at 11:46 AM, Mario Gudelj  wrote:
> I had to do the same thing recently. I had to grab the frequency, interval
> etc. (used rrule for that) and then had to look at the first event instance
> and create multiple instances from that event inside the view. If you create
> a series model and use it as a foreign key in your event to keep on top of
> everything it should work.

You mean it should work with keeping per-date attendance records you mean?

cheers
L.

>
> -m
>
> On 12 September 2012 07:31, Lachlan Musicman  wrote:
>>
>> On Tue, Sep 11, 2012 at 5:15 PM, Jani Tiainen  wrote:
>> >
>> > Rather than creating individual series of events from recurring I would
>> > do a
>> > concept called "recurring event". So it would be just a single event
>> > that is
>> > projected to spesific days as necessary. It requires a slightly more
>> > work
>> > but it's easier to maintain - for example entry would just state:
>> >
>> > recurring = True
>> > frequence = WEEKLY
>> > start_date = 2012-09-11
>> > end_date = 2012-12-01
>> > start_time = 09:00
>> > end_time = 10:00
>> >
>> > Then I would roll out custom non-database concept of "calendar day" that
>> > would be projected from database using both individual entries and
>> > recurring
>> > entries.
>> >
>> > Later on it would be very easy to modify existing recurring events and
>> > for
>> > example add cancellation of single event by creating overriding events
>> > concept.
>> >
>> > This way amount of data will be kept relatively small, it's much easier
>> > to
>> > read and modify. Of course drawback is that you need top level
>> > mechanisms to
>> > work with single calendar entries that map to your database
>> > representation.
>>
>> Great, and obvious, idea - unfortunately a bad fit. Each event needs
>> to be an object as there are student attendance records and staff
>> attendance records linked to each individually.
>>
>> I was thinking about it last night and it occurred to me that instead
>> of using the admin interface I should just write my own form and then
>> do the multiple object creation in the view - it makes sense to me,
>> although I'm sure I've miffed something up.
>>
>> Other ideas still welcome.
>>
>> cheers
>> L.
>>
>>
>>
>> --
>> ...we look at the present day through a rear-view mirror. This is
>> something Marshall McLuhan said back in the Sixties, when the world
>> was in the grip of authentic-seeming future narratives. He said, “We
>> look at the present through a rear-view mirror. We march backwards
>> into the future.”
>>
>> http://www.warrenellis.com/?p=14314
>>
>> --
>> 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.
>>
>
> --
> 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.



-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: Override save or other options?

2012-09-11 Thread Mario Gudelj
I had to do the same thing recently. I had to grab the frequency, interval
etc. (used rrule for that) and then had to look at the first event instance
and create multiple instances from that event inside the view. If you
create a series model and use it as a foreign key in your event to keep on
top of everything it should work.

-m

On 12 September 2012 07:31, Lachlan Musicman  wrote:

> On Tue, Sep 11, 2012 at 5:15 PM, Jani Tiainen  wrote:
> >
> > Rather than creating individual series of events from recurring I would
> do a
> > concept called "recurring event". So it would be just a single event
> that is
> > projected to spesific days as necessary. It requires a slightly more work
> > but it's easier to maintain - for example entry would just state:
> >
> > recurring = True
> > frequence = WEEKLY
> > start_date = 2012-09-11
> > end_date = 2012-12-01
> > start_time = 09:00
> > end_time = 10:00
> >
> > Then I would roll out custom non-database concept of "calendar day" that
> > would be projected from database using both individual entries and
> recurring
> > entries.
> >
> > Later on it would be very easy to modify existing recurring events and
> for
> > example add cancellation of single event by creating overriding events
> > concept.
> >
> > This way amount of data will be kept relatively small, it's much easier
> to
> > read and modify. Of course drawback is that you need top level
> mechanisms to
> > work with single calendar entries that map to your database
> representation.
>
> Great, and obvious, idea - unfortunately a bad fit. Each event needs
> to be an object as there are student attendance records and staff
> attendance records linked to each individually.
>
> I was thinking about it last night and it occurred to me that instead
> of using the admin interface I should just write my own form and then
> do the multiple object creation in the view - it makes sense to me,
> although I'm sure I've miffed something up.
>
> Other ideas still welcome.
>
> cheers
> L.
>
>
>
> --
> ...we look at the present day through a rear-view mirror. This is
> something Marshall McLuhan said back in the Sixties, when the world
> was in the grip of authentic-seeming future narratives. He said, “We
> look at the present through a rear-view mirror. We march backwards
> into the future.”
>
> http://www.warrenellis.com/?p=14314
>
> --
> 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.
>
>

-- 
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: Override save or other options?

2012-09-11 Thread Lachlan Musicman
On Tue, Sep 11, 2012 at 5:15 PM, Jani Tiainen  wrote:
>
> Rather than creating individual series of events from recurring I would do a
> concept called "recurring event". So it would be just a single event that is
> projected to spesific days as necessary. It requires a slightly more work
> but it's easier to maintain - for example entry would just state:
>
> recurring = True
> frequence = WEEKLY
> start_date = 2012-09-11
> end_date = 2012-12-01
> start_time = 09:00
> end_time = 10:00
>
> Then I would roll out custom non-database concept of "calendar day" that
> would be projected from database using both individual entries and recurring
> entries.
>
> Later on it would be very easy to modify existing recurring events and for
> example add cancellation of single event by creating overriding events
> concept.
>
> This way amount of data will be kept relatively small, it's much easier to
> read and modify. Of course drawback is that you need top level mechanisms to
> work with single calendar entries that map to your database representation.

Great, and obvious, idea - unfortunately a bad fit. Each event needs
to be an object as there are student attendance records and staff
attendance records linked to each individually.

I was thinking about it last night and it occurred to me that instead
of using the admin interface I should just write my own form and then
do the multiple object creation in the view - it makes sense to me,
although I'm sure I've miffed something up.

Other ideas still welcome.

cheers
L.



-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: Override save or other options?

2012-09-10 Thread Jani Tiainen

11.9.2012 7:23, Lachlan Musicman kirjoitti:

Hi All,

Simplistically, I have an event type model (for a "school class") with
a date field.

On saving of the first event, I want to add recurring objects.
Specifics for this project are "up to a latest date" (ie, end of term)
and "recur weekly only" (not daily, monthly, yearly, etc - for the
school's weekly timetable)

I have just tried overriding the save method on the object to auto
create these objects.

def save(self):
super(Event, self).save()

last_date = self.term.end_date
series_date = self.date + datetime.timedelta(7)
while series_date < last_date:
   super(Session, self).save(date = series_date)

I've realised that this will most probably not make new objects, but
will only update the date on the current object. Quite separately, I'm
also getting keyword argument error on "date".

How would you go about creating a series of events from a single save
press? Should I be using some sort of external system (celery or ???)
or should I write an additional method for the model that does the
auto-creation?

At some point after working this out, I will have a need to delete the
series as well...and I don't even want to think about editing the
series. Let's start with creating a recurring event and I'll work on
that later.


Rather than creating individual series of events from recurring I would 
do a concept called "recurring event". So it would be just a single 
event that is projected to spesific days as necessary. It requires a 
slightly more work but it's easier to maintain - for example entry would 
just state:


recurring = True
frequence = WEEKLY
start_date = 2012-09-11
end_date = 2012-12-01
start_time = 09:00
end_time = 10:00

Then I would roll out custom non-database concept of "calendar day" that 
would be projected from database using both individual entries and 
recurring entries.


Later on it would be very easy to modify existing recurring events and 
for example add cancellation of single event by creating overriding 
events concept.


This way amount of data will be kept relatively small, it's much easier 
to read and modify. Of course drawback is that you need top level 
mechanisms to work with single calendar entries that map to your 
database representation.



--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
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.



  1   2   3   4   >