Proxy Django models for the admin

in admin.py you cannot register an admin class, and you can only register an imported class once. You CAN register an altered class, but that is an overload on the original registration, so

admin.register(MyClass)
admin.register(MyClass) # Will throw an error and a hissy fit.

However, it is possible to create a proxied class if, for example, you want to have a full set of that class’s attributes and linked classes, and a simple version where you do not load the full set. In a database I maintain, the linked child classes take a long time to load, and are not always necessary.

# In models.py
class CharacterProxy(Character):
 
    class Meta:
        proxy = True
        verbose_name_plural = "Shorter Character Sheet"
 
        ...
# In admin.py
 
# define fieldsets within an AlterCharacter class if you want to reduce them.
admin.register(Character)
admin.register(CharacterProxy)

You can also use a register decorator:

@admin.register(Character)
class CharacterAdmin(admin.ModelAdmin):
    list_display = ("name", "species")
    ...


@admin.register(CharacterProxy)
class CharacterProxyAdmin(admin.ModelAdmin):
    search_fields = ["name"]
    ...

Failure to constrain a database

I was going to write a database that just kept track of a few characters in an RPG, and presented them on as HTML so I could read them off during games.

2000 lines of code, and counting, later…

It keeps tracks of the major affiliations of the gods of the universe, tracks all historical character changes by year and season, takes form input for advancement, generates characters with randomised stats, uses localised in-character geography for alterations based on social groups, includes basic art I have drawn, and has close to no sanity checking. It does output to PDF nicely, though.

My Little Pi-ny

Dev Machine
Here’s the development machine. I love hardware that folds down almost as much as I love free hardware that I picked up because someone else didn’t need it, and this is a blend of the two.

Everything I have in this photo fits into the official touch screen box, along with a chunky battery and a spare USB lead for power. It’s a Pi 3 with blinkt hat, touch screen, Rii-diculously small keyboard on which yes, I genuinely type, and two Fold Holds (by Jonathan Woolf) to hold it all up and protect the screen when it’s packed. You might say the touch screen is overkill – I don’t have a GUI on the machine.

I’m going to design a hat to go on top, which will be able to fly out the unused pins currently covered by the blinkt, giving me breadboarded GPIO access. Nothing could possibly go wrong with that plan.

Clinkt

Pi Larson ScanningI may have got a little carried away.

The Blinkt hat has a perfectly* good python library which does everything you might reasonably want to do with a set of 8 APA102 lights. My problem there is the word ‘reasonably’. So, I re-wrote it in C++, because my soul has never seen the light of day.

(* nearly perfectly. Some might say that flushing the visible buffer by writing white pixels off the end of it is a little much if you decide to define the number of LEDs as 6 for testing and OW MY EYES.)

It’ll take arbitrary pixel length, just like the python library, but unlike the python library it’s built with the assumption you’ll want to make and use multiple patterns, and manipulate those patterns with regard to each other. I can cross over patterns based on whatever input I like, as long as I painstakingly craft that input and sanitise it myself.

The reason I wanted to dig deeper than the python framework was that the Raspberry Pi is my lightweight development machine. I have a laptop that fits into a box. More on that in the next post.

I’m reliably informed that it’s against the law to have a blinkt and not use it to output something something pop culture Davis Hasselhoff – so here is the Larson Scanner in use: Video 19-04-2017, 14 00 28

The C++ library is available at https://github.com/dianaprobst/clinkt. You’ll need the bcm28somethingorother library, but the README.txt has that information. If you want to use cheerlights or APIs you’ll also need libcurl.

blinktenlights

I picked up a pimoroni blinkt in a swag bag recently, and I think I should make a colour clock out of it. There’s a simple one-liner for installation of all required libraries, but it pipes to bash.

That is against my religion. I like to know for myself how I’m messing things up. I like to make sure the checksums are right. Disappointingly, I did it through aptitude, and it didn’t go wrong /at all/.

Lasers

A while back I decided for safety reasons not to put laser cutting capability onto my Art Bot. So, the laser and heatsink bundle arrived today. I’m going to be messing with the voltage and current using a dummy load (also bought that, rather than scraping it together) and nothing could possibly go wrong.

I’ve already written the software.

Kernel Fun

The current linux kernel is messing with the intel graphics chip on my laptop, which consequently thinks it’s helping to run a Cathode Ray Tube, and this is less than perfect.

My options are running a 3 month old kernel, which is perfectly sensible, or using linux-lts, which is also perfectly sensible. So, I’ve gone for the third option. I’m going to have the newest release kernel and also linux-lts as a fallback. This is unusual for me in that it’s a third option that is also perfectly sensible.

However, it does rely on me not building the lts kernel with the wrong name, so as to over-write the kernel I already have. So, I’m going to be here for a while.

It would have gone a lot better if the power lead hadn’t fallen out half an hour before I typed ‘make’.

C++: Cake or Death?

Oddly happy. I’ve got a program where if I run it in the debugger, it completes, and if I run it in the command line it segfaults. This pleases me obscurely.

Yes, I’ve checked it’s the same source file and the same build. No, I’m probably not going to dig into it, I’m just going to fix it and move onto the next problem. However, I’m pleased that I can build something that breaks, because it’s a good step on the road to building something that doesn’t break.

ETA: Wasn’t finding file to make it when edited either. Now is. Still no segfault though.