On 10/04/2020 5:28 pm, אורי wrote:
> Hi,
>
> We are using Django 2.2 and I want to upgrade to Django 3.0. We have a
> mixin (written in 2017) that add fields to forms:
>
> class LocalizedFirstLastNameMixin(object):
> def __init__(self, *args, **kwargs):
> self.language_code = kwargs.pop('language_code','en')
> super().__init__(*args, **kwargs)
> for loc_fieldin reversed(self.get_localized_fields()):
> self.fields[loc_field] = User._meta.get_field(loc_field).formfield()
> self.fields[loc_field].required =True self.fields.move_to_end(loc_field,last=False)
> self.initial[loc_field] =getattr(self.instance, loc_field,'')
>
> It works with Django versions up to 2.2. But when I upgrade to 3.0, I
> get this error message:
>
> AttributeError: 'dict' object has no attribute 'move_to_end'
>
> This function's info:
> '''Move an existing element to the end (or beginning if last==False).
> And it belongs to OrderedDict.
>
> So I guess we want these fields to be in the beginning of the form fields.
>
> Is there a change in the implementation of the fields in forms and how
> do I specify the order of fields? And if I change it, will it work in
> previous versions such as Django 2.2?
I don't know but I recently decided to follow a different path. I think
this has been advocated by Russell Keith-Magee who has (I think) built a
custom user template ... well what I mean is you may not need to go
swapping those fields around and you may even make your project more
attractive to everyone.
Instead of first_name, last_name you adjust your thinking to ...
short_name, full_name
You can use the same fields and only change the way you use them.
Everyone on the planet has a full name and they are the only people who
really know how it should be written. Everyone on the planet may or may
not have a short name they prefer others to use. If they do, they also
know exactly how that should be written.
What Russell was saying is that it is only western nations who have the
first name last name hangup. Software devs have been trying to squeeze
non-western names into first_name, last_name ever since computers were
used to store human data.
I started last century doing the same thing with a switch to swap them.
What a waste of time! There are times you need a short name and every
other time you need the full name exactly as it is written.
I found it remarkably easy to transition.
It would simplify your software and be compatible between 2.2 and 3.x
That'll be 2c
Mike
>
> Thanks,
> Uri.
> אורי
>
u...@speedy.net <mailto:
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...@googlegroups.com
> <mailto:
django-users...@googlegroups.com>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/django-users/CABD5YeEbHc5ewqJKEFAS5XV1JfD%3DEqf8%3D_ScgjhTC5VY2NsDpw%40mail.gmail.com
> <
https://groups.google.com/d/msgid/django-users/CABD5YeEbHc5ewqJKEFAS5XV1JfD%3DEqf8%3D_ScgjhTC5VY2NsDpw%40mail.gmail.com?utm_medium=email&utm_source=footer>.