Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    osxisl
    @osxisl
    Hi, is this chat alive?
    partizan
    @last-partizan
    yes
    Dor Bar
    @dorb4r

    Hey! I have got the Error: cannot import FieldDoesNotExist from "django.db.models"

    I see you merged a fix for that. When will we be able to install it using pip?

    Dor Bar
    @dorb4r
    Just opened an issue for that:
    deschler/django-modeltranslation#561
    partizan
    @last-partizan
    Hi, i'll take a llok right now.
    Released.
    Gikta_python
    @sweetpythoncode
    Hi, is this chat alive?
    partizan
    @last-partizan
    @sweetpythoncode same level of aliveness as github issues, but this is better place to ask questions.
    partizan
    @last-partizan
    @sweetpythoncode so, you want to create a book, with english translation set by default? if it's your default language, you can just create it with objects.create(). And if you want to set fields directly, you use objects.create(title_en="The Little Prince")
    vishal sharma
    @vishal2612200
    Hi Team, Does modeltranslation also support the Hindi language?
    partizan
    @last-partizan
    @vishal2612200 is there something unusual about Hindi? it must work for everything, you just add translations into database
    vishal sharma
    @vishal2612200
    Do I have to add translations manually? I was assuming that it automatically add translations after django-modeltranslation command.
    partizan
    @last-partizan
    @vishal2612200 no, this is module for allowing you to translate fields in your own models
    vishal sharma
    @vishal2612200

    I have some existing project, But when I tried to use modeltranslation it generated an empty field for the model. After that, I tried modeltranslation command to fill out an empty field but it simply populated the empty field with original data, not with a translated version of original data.

    @last-partizan is something that I am missing out.

    I don't know why the translated version of the original data doesn't add up to the newly generated fields.

    @last-partizan How can I get out from this problem.

    Is there any previous project example on GitHub that have used modeltranslation in it, So that I can take out a reference from that. It would be really helpful for me.
    partizan
    @last-partizan
    @vishal2612200 modeltranslation does not translate your data, you must do it yourself.
    vishal sharma
    @vishal2612200

    Thanks, @last-partizan, Great to have a talk with you. Now I have the answer to my most of the answers to the question.

    I have already read out the whole documentation, All contributors have done great work. Thanks for your contribution to open-source.

    partizan
    @last-partizan
    @vishal2612200 you're welcome! :)
    vishal sharma
    @vishal2612200
    :)
    vishal sharma
    @vishal2612200

    @last-partizan , How can I use the field that I was using before the modeltranslation.

    For example,

    In setting.py, I have defined the following thing,

    LANGUAGES = (

          ('hi', gettext('Hindi')),          

    )

    So after this my templates are showing 'hi' fields,

    for example, they are showing the content of 'title_hi', but I want to show 'title' content, not 'title_hi', how can I do this?

    I don't want the '_hi' should overtake my original content.

    partizan
    @last-partizan
    @vishal2612200 you should add two languages, one of which is the language of original text
    vishal sharma
    @vishal2612200
    Okay, Thanks @last-partizan :)
    vishal sharma
    @vishal2612200

    Hi @last-partizan ,

    I have some queries related to the django-rest-framework method integration with django-modeltranslation.

        def get_queryset(self):
            user_language = self.request.GET.get('language')
            return Model.objects.get_language(user_language).all()

    For example, can I get particular language data similar to this '?language=en'?

    partizan
    @last-partizan

    @vishal2612200 hi

    django-modeltranslation uses current language from django, i suppose it's better to use something like LocaleMiddleware

    https://docs.djangoproject.com/en/3.1/ref/middleware/#module-django.middleware.locale

    or if you want direct approach, something like this:

    def list(self, request, ...):
        lang = ...
        with translation.activate(lang):
            return super().list(request, ...)
    vishal sharma
    @vishal2612200
    Thanks, @last-partizan, It worked for me:)
    Suhrob Malikov
    @malikovss
    hi there!
    how should be my model serializer? any example?
    please can u help me. I couldn't find from google
    partizan
    @last-partizan
    @malikovss Hi. Just normal model serializer, nothing special i think.
    partizan
    @last-partizan
    Q: What does base-class approach mean in the documentation? #579
    A: Using base class, like "TranslatableModel" for all your translated models.
    UP
    @banDeveloper
    Hello, I can use the module fine with the default sqlite DB, but when I use postgreSQL 13 the fallback functionality does not work. I used a fresh DB and the same settings, the module works fine, but MultilingualQuerySet returns empty when no current language values are present - no fallback values. Simply switching back to a fresh sqlite DB makes it work again, but no matter what it just will not work with postgreSQL. Anyone with similar problems?
    partizan
    @last-partizan

    Hmm, i should work just fine.

    I'm using it with mysql, and not tested presonally with postgres. Are you sure databases has the same content? try comparing Model.objects.values("field", "field_lang") for sqlite and postgres

    UP
    @banDeveloper
    You're right, it has nothing to do with the database type. I think I simply don't understand the functionality well enough. I assumed that fallback would work in all of the following cases, but it returns empty in some instances. Can you help me understand why/ how to enable fallback functionality for such caes?
    >>> from django.utils import translation
    >>> from blog.models import Post
    >>> translation.get_language()
    'sl'
    >>> post_slo = Post.objects.create(title='Slo')
    >>> translation.activate('en') 
    >>> translation.get_language()
    'en'
    >>> post_eng = Post.objects.create(title='Eng') 
    >>> translation.activate('sl')
    >>> p = Post.objects.values('title', 'title_sl', 'title_en')
    >>> p
    <MultilingualQuerySet [{'title_sl': 'Slo', 'title_en': None, 'title': 'Slo'}, {'title_sl': None, 'title_en': 'Eng', 'title': 'Eng'}]>
    >>> p = Post.objects.filter(title__startswith='Sl').values('title', 'title_en', 'title_sl')
    >>> p
    <MultilingualQuerySet [{'title_sl': 'Slo', 'title_en': None, 'title': 'Slo'}]>
    >>> translation.activate('en')
    >>> p = Post.objects.values('title', 'title_sl', 'title_en')
    >>> p
    <MultilingualQuerySet [{'title_sl': 'Slo', 'title_en': None, 'title': 'Slo'}, {'title_sl': None, 'title_en': 'Eng', 'title': 'Eng'}]>
    >>> p = Post.objects.filter(title__startswith='Sl').values('title', 'title_en', 'title_sl')
    >>> p
    <MultilingualQuerySet []>
    >>> translation.activate('sl') 
    >>> p = Post.objects.filter(title__startswith='En').values('title', 'title_en', 'title_sl') 
    >>> p
    <MultilingualQuerySet []>
    partizan
    @last-partizan
    @banDeveloper honestly i don't understand how it works. Take a look at str(Post.objects.filter(title__startswith='En').query) to see what actual query is
    remo001
    @remo001:matrix.org
    [m]
    how to work with modeltranslation in DRF?
    I push queryset to serializer and get "error, multilanguage queryset, but list of dict needed"
    partizan
    @last-partizan

    Show full traceback.

    It should work out of the box.

    remo001
    @remo001:matrix.org
    [m]
    serializer = self.get_serializer(
                data=queryset, many=False, context={"lang": language}
            )
    {'non_field_errors': [ErrorDetail(string='Invalid data. Expected a dictionary, but got MultilingualQuerySet.', code='invalid')]}
    serializer = self.get_serializer(
                data=queryset, many=True, context={"lang": language}
            )
    {'non_field_errors': [ErrorDetail(string='Expected a list of items but got type "MultilingualQuerySet".', code='not_a_list')]}
    partizan
    @last-partizan
    Show your serializer
    Oh, wait
    You shouln't use data.
    data is for input data, like list of items
    serializer = self.get_serializer(queryset, many=True) should work
    remo001
    @remo001:matrix.org
    [m]

    serializer = self.get_serializer(
    queryset,
    many=True,
    context={"lang": language},
    )

    is work, thanks

    Now I get all field from table

    how to multilang fields in query?
    partizan
    @last-partizan
    what?