Coder Social home page Coder Social logo

juanpex / django-model-i18n Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gonz/django-model-i18n

20.0 20.0 7.0 441 KB

Model translations with a pluggable twist

Home Page: http://juanpex.github.com/django-model-i18n/

License: BSD 3-Clause "New" or "Revised" License

HTML 11.29% Python 88.71%

django-model-i18n's People

Contributors

bitdeli-chef avatar gonz avatar jfunez avatar juanpex avatar marcelor avatar supervacuo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

django-model-i18n's Issues

Admin integrated translations

Hello Juanpex,
I have try the app and i think it is the best approach to a translation system for django. I have made an example, and i can see the tables new_translation and new_translations, but i cant see any way to fill them from the admin. My admin file for this app has the following code:

from django.contrib import admin
from .models import New

admin.site.register(New)

I have configured the languages in settings:

LANGUAGES = (
  ('en', 'English'),
  ('es', 'Español'),
  ('fr', 'Français'),
)
LANGUAGE_CODE = 'es'

and the model is quite simple:

from django.db import models

class New(models.Model):
    title = models.CharField(max_length=50)
    subtitle = models.CharField(max_length=256, null=True)    
    image = models.ImageField(upload_to = 'news', null=True, blank=True)

but it does not show the subforms for the translation in the admin.

Translation with custom model manager

Hi, I think I finally found the issue that I had a hard time identifying.

I have a few models that define or use custom managers.
It would seem that, in such cases, we lose the translation...

Here's an example:

app/models.py:

class MyClassManager(models.Manager):
    def get_query_set(self):
        now = timezone.now()
        return super(MyClassManager, self).get_query_set()
    def get_active(self):
        now = timezone.now()
        return super(MyClassManager, self).get_query_set() \
                .filter(status='p') \
                .filter(end_date__gte=now)        def get_active(self):

class MyClass(models.Model):
        text = models.CharField(...)
        status = CharField(...)
        end_date = models.DateTimeField()
        objects = active = MyClassManager()

app/translations.py:

from model_i18n import translator     # django-model-i18n
from .models import Announcement

class AnnouncementTranslation(translator.ModelTranslation):
    fields = ('title','body')
translator.register(Announcement, AnnouncementTranslation)

app/views.py:

class DetailView(generic.DetailView):
    ...
    def get_context_data(self, **kwargs):
        context = super(DetailView, self).get_context_data(**kwargs)
        context['c1'] = MyClass.objects.get_active().filter(field=...)   # not translated
        context['c2'] = MyClass.active.filter(field=...)   # not translated either

apps/templates/app/detail.html:

{% load_i18n %}
{% mycontext %}

I'm not sure I'm doing everything right...
I didn't want to override get_query_set directly because there are cases where I want objects to remain unfiltered.
Any idea?

Recent change breaks project using dynamically generated settings.

Hi Juanpex,

The follow change assumes that the settings module will point to a file located in the base of the project directory. It causes the app to break when installed into projects that don't have a traditional settings.py file. I'm not clear as to why to made this change but it's causing my site to break.

project_dir = path.dirname(import_module(settings.SETTINGS_MODULE).__file__)

Just trying to better understand. Thanks,
Kenzic

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.