Re: Busqueda de Django admin

2016-03-27 Thread Luis Zárate
https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.search_fields

Si no es eso tiene que explicar mejor que es lo que necesita.

Además recuerde que esta lista es en inglés.


2016-03-27 16:00 GMT-06:00 :

> Necesito saber como modificar la búsqueda que viene por defecto en el
> módulo de administración de Django.
>
> --
> 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/8ef9f585-5114-41c1-8071-994c109d96fc%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
"La utopía sirve para caminar" Fernando Birri

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


Django's search

2016-03-27 Thread lzamorano03
I need know how change the search that come with Django's Admins.

-- 
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/82788600-1519-4347-8634-6420b166ca93%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Busqueda de Django admin

2016-03-27 Thread lzamorano03
Necesito saber como modificar la búsqueda que viene por defecto en el 
módulo de administración de Django.

-- 
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/8ef9f585-5114-41c1-8071-994c109d96fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How delete from HTML?

2016-03-27 Thread Seti Volkylany

How delete  from my text in html element for code 
 with pysegments (style monokai)

class UpdateAccountInfo(LoginRequiredMixin, View):

View for update information about account of user


def post(self, request, *args, **kwargs):
if request.is_ajax():
result = dict()
status = 200
try:
if request.FILES:
coordinates_x1 = 
int(request.POST.get(coordinates[x1]))
coordinates_y1 = 
int(request.POST.get(coordinates[y1]))
coordinates_x2 = 
int(request.POST.get(coordinates[x2]))
coordinates_y2 = 
int(request.POST.get(coordinates[y2]))
field = account_user_info-picture
value = request.FILES[field]
new = {field: value}
account_info = 
AccountUserInfo.objects.get(account=self.request.user)
account_info.picture = value
account_info.full_clean()
account_info.save()
picture_file = Image.open(account_info.picture.path)
cropped_picture = picture_file.crop([coordinates_x1, 
coordinates_y1, coordinates_x2, coordinates_y2])
cropped_picture.save(account_info.picture.path)
result[new_image_url] = account_info.picture.url
else:
field = self.request.POST[field]
value = self.request.POST[value]
if field == datetimepicker_for_birthday_account:
correct_field = birthday
else:
correct_field = 
field.replace(account_user_info-, )
new = {correct_field: value}
account_info = 
AccountUserInfo.objects.filter(account=self.request.user)

AccountUserInfo(**new).full_clean(exclude=[account])
account_info.update(**new)
account_info = 
AccountUserInfo.objects.get(account=self.request.user)
result[new_value_progresbar_filling_account_info] = 
account_info.filling_account_info()
except BaseException as errors:
result = dict(errors)
status = 400
return JsonResponse(data=result, status=status)

-- 
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/3d900331-0681-40a2-92cb-e214d0354783%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Model design

2016-03-27 Thread Bob Gailer
On Mar 27, 2016 9:41 AM, "Paria Parsamanesh" 
wrote:
>
> Hi ,
> I am new to Django and python and I want to connect to cloudera metadata
database (postgre. )
> I have background in java, and db2, to design java model classes , we
used logical data model and create UML modeling tools. .
>
> Can you direct me on
> 1) How to make this connect from Django on windows to Cloudera postgre.
I am not an expert. My guess is you will accomplish this via settings.py.
> 2) How to design model classes.
Start with the Django tutorial. This will give you the basics. Then look at
the models section of the documentation. Start to build a model.py, then
come back with questions.

Just my opinion. Others may have other ideas.

-- 
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/CAP1rxO7_f2Yj0uasxutn86qZG36bO-c4coA5-3KEgxF%3DN-Qxqg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generate different querysets depending of the website language

2016-03-27 Thread Daniel Chimeno
Hello again,
In that case, I would double-check the middleware process and settings in 
your project.
One reason could be your are placing LocaleMiddleware after your 
ForceDefaultLanguage,
so https://github.com/django/django/blob/master/django/middleware/locale.py#L26
is setting the default language.

Hope it helps.
 
El sábado, 26 de marzo de 2016, 20:43:09 (UTC+1), Mathieu Poussin escribió:
>
> Hello,
>
> I have an issue, I am creating a website that will be available in many 
> languages, sharing the same database.
> Most models have a "language" attribute that is the 2 letters from the 
> language code (en, es, fr, etc.).
>
> I am trying to find a way to show the correct content per language.
>
> I tried many things, creating a custom manager :
>
> from django.utils.translation import get_language, get_language_info
> from django.db import models
>
> class PerLanguageManager(models.Manager):
> def get_queryset(self):
> if get_language():
> return super(PerLanguageManager, self).get_queryset().filter(
> language=get_language_info(get_language())['code'])
> else:
> return super(PerLanguageManager, self).get_queryset()
>
>
> Or overriding get_queryset using another method : (The language is always 
> present in the url as /en/ or /es/) 
>
> class RecipeIndexView(generic.ListView):
> paginate_by = 10
>
> def get_queryset(self):
> return 
> Recipe.objects.filter(language=get_language_from_request(self.request, 
> check_path=False))
>
> But nothing work, I always get the default configured language (even if 
> with the debug toolbar tell me the site is in another language, and all the 
> translations are correctly done in the language specified in the URL, I 
> always get the default language from the queries...)
>
> I'm using a specific middleware to ignore the language specified in the 
> browser to only use the language specified in the URL :
> class ForceDefaultLanguageMiddleware(object):
> """
> Ignore Accept-Language HTTP headers
>
> This will force the I18N machinery to always choose 
> settings.LANGUAGE_CODE
> as the default initial language, unless another one is set via 
> sessions or cookies
>
> Should be installed *before* any middleware that checks 
> request.META['HTTP_ACCEPT_LANGUAGE'],
> namely django.middleware.locale.LocaleMiddleware
> """
> def process_request(self, request):
> if 'HTTP_ACCEPT_LANGUAGE' in request.META:
> del request.META['HTTP_ACCEPT_LANGUAGE']
>
>
> Any idea of how to make this work ? What is the good way to do this ?
>
> Thank you.
> Mathieu
>
>

-- 
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/66d4859d-d61b-46ca-b3a0-3232da1c4786%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django Model design

2016-03-27 Thread Paria Parsamanesh
Hi ,
I am new to Django and python and I want to connect to cloudera metadata 
database (postgre. )
I have background in java, and db2, to design java model classes , we used 
logical data model and create UML modeling tools. .

Can you direct me on
1) How to make this connect from Django on windows to Cloudera postgre.
2) How to design model classes.
 
Thank you
Paria

-- 
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/fac0c25e-8955-4711-b61d-71505b4a51f0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generate different querysets depending of the website language

2016-03-27 Thread Mathieu Poussin
Thanks for the tips about the translation module, in my case, I think it 
would be better to keep managing it the way I do as each models have 
complex relation with other models that are only bound to a specific 
language of the model (Like tags, comments, steps (This is about recipes), 
etc.
I also suppose that would break stuff like Reversion or Haystack (I prefer 
to keep my models as simple and standard as possible).

The weird thing is that, when I switch to a language, everything work fine, 
except dynamic queryset, exemple :
I go to "/en/r/" (The main recipe list), I expect to only see the english 
recipes, but I get the Spanish ones in all cases (This is the default 
language), but I can see that everything else is translated correctly to 
english, and the HTTP header response tell me the page is in English, so I 
think the problem is really in my queryset, why is it always selecting the 
default language just for the queryset when everything else is translated 
correctly ?

Thanks.
Mathieu

On Sunday, 27 March 2016 04:49:20 UTC+2, Daniel Chimeno wrote:
>
> Hello,
>
> If you are able to change the schema I would suggest you to use 
> modeltranslation [https://github.com/deschler/django-modeltranslation],
> also the source code of that app can help you in order to take an specific 
> approach to your project.
>
> About the URL's, if you use i18urls, it has priority over the http headers 
> [
> https://docs.djangoproject.com/en/1.9/topics/i18n/translation/#module-django.conf.urls.i18n]
>  
> (Not confirmed, but was true last time I checked it)
>
>
> Hope it helps.
>
> El sábado, 26 de marzo de 2016, 20:43:09 (UTC+1), Mathieu Poussin escribió:
>>
>> Hello,
>>
>> I have an issue, I am creating a website that will be available in many 
>> languages, sharing the same database.
>> Most models have a "language" attribute that is the 2 letters from the 
>> language code (en, es, fr, etc.).
>>
>> I am trying to find a way to show the correct content per language.
>>
>> I tried many things, creating a custom manager :
>>
>> from django.utils.translation import get_language, get_language_info
>> from django.db import models
>>
>> class PerLanguageManager(models.Manager):
>> def get_queryset(self):
>> if get_language():
>> return super(PerLanguageManager, self).get_queryset().filter(
>> language=get_language_info(get_language())['code'])
>> else:
>> return super(PerLanguageManager, self).get_queryset()
>>
>>
>> Or overriding get_queryset using another method : (The language is always 
>> present in the url as /en/ or /es/) 
>>
>> class RecipeIndexView(generic.ListView):
>> paginate_by = 10
>>
>> def get_queryset(self):
>> return 
>> Recipe.objects.filter(language=get_language_from_request(self.request, 
>> check_path=False))
>>
>> But nothing work, I always get the default configured language (even if 
>> with the debug toolbar tell me the site is in another language, and all the 
>> translations are correctly done in the language specified in the URL, I 
>> always get the default language from the queries...)
>>
>> I'm using a specific middleware to ignore the language specified in the 
>> browser to only use the language specified in the URL :
>> class ForceDefaultLanguageMiddleware(object):
>> """
>> Ignore Accept-Language HTTP headers
>>
>> This will force the I18N machinery to always choose 
>> settings.LANGUAGE_CODE
>> as the default initial language, unless another one is set via 
>> sessions or cookies
>>
>> Should be installed *before* any middleware that checks 
>> request.META['HTTP_ACCEPT_LANGUAGE'],
>> namely django.middleware.locale.LocaleMiddleware
>> """
>> def process_request(self, request):
>> if 'HTTP_ACCEPT_LANGUAGE' in request.META:
>> del request.META['HTTP_ACCEPT_LANGUAGE']
>>
>>
>> Any idea of how to make this work ? What is the good way to do this ?
>>
>> Thank you.
>> Mathieu
>>
>>

-- 
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/dbb9dff6-c89b-40ca-9277-f6f24938eaa3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django tutorial part 3 - question_id vs question.id

2016-03-27 Thread James Schneider
>
> In trying to update my templates after I successfully finished part 3 of
> the tutorial, I found that I could write something like
> You're looking at the results of question {{ question.id }}: "{{
> question.question_text }}"
> and get: You're looking at the results of question 1: "What's up?"
>

This worked by accident in your particular situation. The 'id' of the
object is a reference to the data row in the database, and is not intended
for human consumption in most cases (ie direct display in the template to
the end-user). If you created more questions, the ID would increase. You
should not rely on it to 'number' your questions, rather number the
questions yourself (either manually or via something like
django-ordered-model). Using the ID, there's no way to a) renumber
questions in a different order or b) group questions together via other
attributes such as a 'question group', where you would want the numbering
for your questions to start over (presumably).


>
> However, if I write
> You're looking at the results of question {{ question.question_id }}:
> "{{ question.question_text }}"
> I get: You're looking at the results of question : "What's up?"
>

> I think the answer is that "The template system uses dot-lookup syntax to
> access variable attributes. In the example of {{ question.question_text }},
> first Django does a dictionary lookup on the object question."  And "id"
> is an attribute of the question object.  But if that's the case, then why
> is "question_id" used everywhere else (views.py, urls.py)?  Is it because
> we *define* the question_id parameter by the pattern of the incoming
> request in views.py?  In other words, if we changed ?P to
> ?P, then we would be writing our views like this:
> def detail(request, my_favorite_number):
> question = get_object_or_404(Question, pk=my_favorite_number)
> but still referencing the id as {{ question.id }} in our templates?
>
>
"question_id" and question.id are referring to very different things. The
reason that {{ question.question_id }} didn't work is because there is no
attribute/method/property on "question" called "question_id". The template
system will return an empty string in those cases where it can't resolve a
value. There is a magic shortcut that might be causing some confusion
(explained below).

Within the views, "question_id" is referring to the kwarg that was captured
by the URL regex (through the regex capture group of the same name), and is
literally just a number (captured as a string). It is used as part of the
.filter() or get_object_or_404() call to pull the object with the database
ID of whatever the value of "question_id" is (which is coerced in to an
integer if it hasn't been already internally).

You are correct in your assertion about changing the name of the capture
group and the view argument and the reflected changes in the
get_object_or_404() call. However, "my_favorite_number" is exactly that,
just a number. Remember, "question_id" is simply a variable name that lives
within the context of your view, that's it.

Now moving on to "question". Once the get_object_or_404() call is made,
"question" becomes a fully populated Question object, rather than just a
number. You can modify it and run .save() to keep the changes in the
database, which you can't do with just "question_id". The "question" in
your view is then passed along via the template context as "question". It
is possible to change the name of the variable that holds your Question
object in the template vs. the view. In fact, this is exactly what the
class-based views are doing behind the scenes, and every reference to the
primary object of interest (in this case, a Question object) in a template
populated by a CBV is called {{ object }} within the template.

Template naming tricks aside, all of the calls within your template to {{
question }} are for an actual Question object. Question objects (per the
tutorial models) have no attribute/field called "question_id", hence the
reason your template didn't display anything.


To confuse things more, Django does offer some optimization shortcuts for
related fields. For example, if you were working with a Choice object in a
variable called "choice", you can access the database ID of the related
question in two ways (in either a view or a template):

choice.question.id
choice.question_id

Both of these calls will result in the same value, the database ID of the
Question model that the Choice belongs to. However, there is a big
difference in how they get there.

The first is the "standard" way to access information about related
objects. The ORM tries to be lazy, so it doesn't try to fetch anything
about the related Question unless needed (ie accessing anything
choice.question.*). The first time it is called, a database hit is incurred
to populate the Question object that is related to the Choice object. Once
the Question object is populated, the ID of that object is returned.

The second is less-known, but