Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Glad you enjoyed it. I will just correct you:
DateTimeField
should not accept string, no string format in tests. In tests you can find only that it can accpetdatetime.datetime
instance. Alsodatetime
module is imported for you and it's also in description (note thatdatetime.datetime
is not module,datetime
is).No, test is just allright. I don't want to be spoiler, but model looks like that:
And that
foo
have to be same without any change.Test looks like that:
Dunno why it still raises AttributeError. Anyway you have to change only fields on class. You have to leave another attributes alone. In metaclass you will get whole dict of class - all attributes and all methods. You should manipulate only with fields. If you change something else, it will fail.
Pardon me, I haven't time visit CodeWars for few days.
Test #4 for
DateTimeField
was another implementation detail. I removed it.Well, you need to be careful before you do something with original code by metaclass. You should add syntactic sugar for fields, nothing else. I improved tests, so now you shold see better message.
That's very disappointing. Thank you anyway! :-)
What regexp module is available for Haskell?
Text.Regex
doesn't work for me.By the way some Field should fail with value
None
and some not. It depends on "setting" of model. If you look at this model:For first name it shouldn't allow value
None
, but it should for last name. So this piece of code will go without raising any exception:You are right. I made tests for solutions how it's implemented in Django. But someone can have different solutions, so I edited tests so it tests only final solutions as is described and not implementation details.
I was thinking about 1kyu, but this kata uses really basics of Metaclass (in fact just one thing), so I suppose it's 2kyu.
Try this help: if I say it simple (not very correctly, but most of people can understand to this) - like classes creates instances, metaclasses creates classes. So by metaclass you can change behavior of creating classes which is needed in this kata. You in fact doing some syntactic sugar for your own framework.
Those tests are saying you don't want mix some Field definition in you final code. When you use your model like user, you want to have just fields with normal values. Like you would write something like this:
And your model should help you out with not writing this code again and again for every model.
Tell me what do you think about this description and I will add this to description. :-)
I thank you for feedback as well. :-)
I adjusted example test cases, but it doesn't work to reset when you already started... be sure that when someone else start this kata, it will be allright. It wouldn't allow me to publish if it wouldn't pass.
In Django
clean
method does validation and sometimes it can change values. Therefor it's calledclean
. I used same name, but in the end I used only validation for simplification. I changed name of method tovalidate
so it is understandable even by someone who don't know Django.In description is example what it should do with list of what you have to implement. I tried to open some test cases. Hope, it's clearer now. If you still don't know, let me know. But of course, it's not easy one. This kata is intended to play with metaclasses and find out how it is helpful for frameworks like Django.