django-oscar categories and products translations - django

I want to use django-oscar for building an web shop and this shop will provide two main languages.
Oscar's translations do very well with regular fields like View chart or Add to chart, but does not support custom elements e.g. Categories or Product's Titles.
I want have translated:
Category
Product.Title
Product.Description
I've figured out two approaches:
Approach one - modify django-oscar templates
I can create custom set of tranlsations according to oscar's translation doc.
And then fill proper django.po file with translated categories and product's titles.
Unfortunately I will have to overwrite some templates, because they don't use trans templatetag by default. E.g. I would change.
{{ category.name }}
to
{% trans category.name %}
In this oscar's template.
Main problem with this approach is need for overwriting templates, updating django.po as well as compiling it with every new entry to translate.
Approach two - use django-modeltranslation
Using this plugin.
Question
Does I miss some build in django-oscar's feature, or I have to use one of above approaches?

Using django-modeltranslation was a good idea.
Even updating dashboard according to customization instructions from oscar's docs and ModelForm description from modeltranslation's docs done the job well.

Related

Is it possible to display the HTML provided by the admin panel app on-site?

I've built a site where I can create new posts (essays) by the admin panel. The output is visible to users. But when I place some HTML as content in the form it doesn't render itself on the page.
example:
Output on the page (with marked unrendered HTML):
I would like to know how to fix it and also, how to name the topic I want to know ( I couldn't find anything related to my problem, probably because I don't know how to express it).
Additionally, I just start to wonder if there is one more problem nested inside. How to link CSS from the static folder having this HTML mentioned above?
Django offer the autoescape template in the builtins tags
{% autoescape off %}
{{ myhtml }}
{% endautoescape %}
But your logic seems wrong, you don't need to create a new page with the doctype, just create a base template and use the block content tag to insert your article.
In your base template replace the description and title of your page by variables that will be populated by the article data.
You need to learn the basic of Django https://docs.djangoproject.com/en/4.1/ trust me you won't regret it !

Does django support separating your templates into parts?

I would like to create separate templates for each part of the page like Navigation, Side bar, Login panel, etc. Django seems to use inheritance rather than composition. I was wondering if there is any support for separating templates out into parts and passing in template specific models to each template. I'm thinking of something like:
values = {
'navbar_data' = ...
'sidebar_data' = ...
}
{{ template.render('navbar', navbar_data) }}
{{ template.render('sidebar', sidebar_data) }}
There are many good ways to do this.
You can use the builtin templatetage include for this. This template tag allows you to to use and reuse specific fragments of a template. This is usually most useful for mini templates that say represent a single model and will be used throughout the site. This can be especially useful if you combine it with the with templatetag to allow you to craft the context used in the included template
Alternatively just simply using block may give you the feel you're looking for
Finally you can use custom inclusion templatetags (https://docs.djangoproject.com/en/1.4/howto/custom-template-tags/#inclusion-tags) to give you an even deeper level of control. These will allow you to render a subtemplate with a completely custom context.
That is what templatetags are for. You define a tag in a file called myapp/templatetags/mytags.py, then in your template do this
{% load mytags %}
{% navbar %} {% sidebar %}
The official documentation has plenty of information about this.

Putting links in list_detail.object_list to list_detail.object_detail

I've started using Django and am going right to generic views. Great architecture! Well, the documents are great, but for the absolute beginner it is a bit like unix docs, where they make the most sense when you already know what you're doing. I've looked about and cannot find this specifically, which is, how do you set up an object_list template so that you can click on an entry in the rendered screen and get the object_detail?
The following is working. The reason I'm asking is to see if I am taking a reasonable route or is there some better, more Djangoish way to do this?
I've got a model which has a unicode defined so that I can identify my database entries in a human readable form. I want to click on a link in the object_list generated page to get to the object_detail page. I understand that a good way to do this is to create a system where the url for the detail looks like http://www.example.com/xxx/5/ which would call up the detail page for row 5 in the database. So, I just came up with the following, and my question is am I on the right track?
I made a template page for the list view that contains the following:
<ul>
{% for aninpatient in object_list %}
<li><a href='/inpatient-detail/{{ aninpatient.id }}/'>{{ aninpatient }}</a></li>
{% endfor %}
</ul>
Here, object_list comes from the list_detail.object_list generic view. The for loop steps through the object list object_list. In each line I create an anchor in html that references the desired href, "/inpatient-detail/nn/", where nn is the id field of each of the rows in the database table. The displayed link is the unicode string which is therefore a clickable link. I've set up templates and this works just fine.
So, am I going in the right direction? It looks like it will be straightforward to extend this to be able to put edit and delete links in the template as well.
Is there a generic view that takes advantage of the model to create the detail page? I used ModelForm helper from django.forms to make the form object, which was great for creating the input form (with automatic validation! wow that was cool!), so is there something like that for creating the detail view page?
Steve
If you're on django < 1.3 then what you are doing is basically perfect. Those generic views are quite good for quickly creating pages. If you're on django 1.3 you'll want to use the class based generic views. Once you get a handle on those they are are crazy good.
Only note I have is that you should use {% url %} tags in your templates instead of hardcoding urls. In your urls.conf file(s) define named urls like:
url('inpatient-detail/(?P<inpatient_id>\d+)/$', 'your_view', name='inpatient_detail')
and in your template (for django < 1.3):
...
In 1.3 a new url tag is available that improves life even more.

How do I create a filtered Dropdown Choice field in Django using ajax?

I am trying to create a dynamic filtered drop down choice fields,i gone through below blog but it confusing,can any one suggest easy way to do this in django.
I'm trying to create a dynamically filtered dropdown Choice field in Django. I've tried the steps outlined here, but I don't understand it.
How do I create a filtered Dropdown Choice field in Django using ajax?
You can use dajaxproject (django+ajax). Example: http://www.dajaxproject.com/forms/ It's so easy.
Maybe you mean something like this?
http://code.google.com/p/django-ajax-selects/
I have this implemented in a couple of projects, and it's working well. If you are looking for a kind of search form for foreign keys, have a look at an app I started some weeks ago:
https://github.com/schneck/django-foreignkeysearch
I only had a small array of drop down choices I needed to display, so I chose to be lazy and not to go the Ajax route but rather used the initial example provided in the blog (his prototype). This will slow down rendering the page if you have many drop-down choices, which I do not have.
The way it worked for me was that I replaced the array:
modelstxt[1] = "1\tEscort\n2\tTaurus";
modelstxt[2] = "1\tAltima\n2\tMaxima";
With template tags that will create the same array while building the page (note I use locations and areas, not models and makes):
areastxt[0] = "0\t--";
{% for location in locations %}
areastxt[{{location.id}}] = "0\t--
{% for area in areas %}
{% if area.location_id == location.id %}
\n{{area.id}}\t{{area.name}}
{% endif %}
{% endfor %}";
{% endfor %}
Disclaimer: I am noob'ish, so I may be committing a noob faux-pas using this approach.

Flickr albums in django admin

I want to do the following:
Having a model (p.e. a model which handles data about photographic reports) create a section which has a preview of an specific flickr album. The URL will be provided by an URLField (until the first save the preview will not be available).
After the first save, it'll show previews of all the images inside that album, and make them selectable (through jQuery for example). Then again, when the images are selected and the object is saved (I think I can use django signals for this) it will notify a specific user telling him a selection has been made.
Is there any plugins available, or any easy way to implement this in django-admin?
Update: 22 days and no anwers... does that mean it can't be done in django-admin?
I personally can't think of any easy way to implement this in the Django admin, simply because I doubt many people who've done it have thought to open source it. I can imagine that it would be very specific to a certain user's / programmer's needs.
In any case, if you wanted to solve this issue, I'd say that your best bet would be overriding the Django admin templates in your django/contrib/admin/templates/admin folder. I believe you'd be best off by editing change_form.html.
My basic approach would be this:
Check the name of the model using opts.verbose_name. For example, if you wanted to do this processing for a model whose verbose name is "Gallery", you would do
{% ifequal opts.verbose_name "Gallery" %}
<!-- neat gallery view -->
{% else %}
<!-- regular form -->
{% endifequal %}
Make a custom template tag that will display the gallery view / form given the object_id and the type of object. This way you can replace the <!-- neat gallery view --> with a {% show_gallery object_id %}. See the Django Docs for more info on creating custom template tags. It's pretty straightforward.
Add whatever Javascript or custom stuff in your template tag template. What you choose to do is up to you.
Sorry you haven't gotten many more answers to your question. Hope this helps!