Blog


7 Comments

No, your cell phone does not have a Facebook name

02.07.12 Posted in The Web by

your cell phone has a facebook nameAn obnoxious yellow image saying Your Cell Phone has a name! has made its way onto my newsfeed with thousands of comments. I tried it myself on my own status (because I’m not keen on liking or commenting on public feeds), and I got “Matt Moon.” Now, this guy’s name is popping up for those whose phone numbers end in 409. His profile ID number is actually 409: http://www.facebook.com/profile.php?id=409. I figured this was some code thing with the @[] tags, so I popped in the number for the Facebook profile url. You can use numbers from 100 to 999. Any numbers below 100 or above 999 seem to not work.

You will also notice that several of these people graduated from Harvard – where Facebook began – so their profile IDs would have low numbers, compared to mine which is 355571664452867. I joined Facebook around 2006!

Sorry, everyone. This isn’t Facebook magic, but whoever came up with this is quite the jokester!


2 Comments

Where is the very important ‘excerpt’, WordPress 3.3.1?

01.30.12 Posted in The Web by

I was freaking out, people! Using WordPress version 3.3.1, I thought WP got rid of the Excerpt table. Besides the title, the excerpt is simply one of my favorite SEO tools.

So, I missed this part. Just click on Screen Options at the top right corner when creating a new post and select the fields you want shown on the screen. I’ve enabled them all.

screen options wordpress

The excerpt field is disabled by default in WordPress 3.1+ if you hadn’t previously used it. I’ve always used it, and having installed a new WordPress on this site, I didn’t know this happened. But phew!


1 Comment

How to prepopulate a slug field from a foreign key in Django

01.29.12 Posted in The Web by

The Emma Frost Comic Book Database was my first Django project when I was familiarizing myself with the web framework and the Python programming language.

The models for the comic book database seemed relatively easy, but I came across problems that I didn’t consider, such as prepopulating a slug field from a foreign key. The comic book Title is a foreign key that goes into the Issue model. Selecting a title from a drop-down list should automatically prepopulate the slug field if defined in the admin.py, right? Nope, it comes up blank and will only prepopulate character fields – which is most likely a front-end Javascript issue.

Thanks to Justin Myers, he came up with a simple, bang-your-head-on-the-desk solution for generating slugs from foreign keys that I’d like to share since it is a common question.

Here’s how to do it, given an abbreviated example of my models.py file:

class Title(models.Model):     title = models.CharField(max_length=64)     slug = models.SlugField()     def get_absolute_url(self):         return "/titles/%s" % self.slug     def __unicode__(self):         return self.title class Issue(models.Model):     title = models.ForeignKey(Title)     number = models.CharField(max_length=20)     slug = models.SlugField(blank=True)     def __unicode__(self):         return u'%s #%s' % (self.title, self.number)     # Here is where the code you need starts.     def save(self, *args, **kwargs):     # Creates the slug, including the foreign key's slug.         self.slug = str(self.title.slug)         # Calls the parent save()         super(Issue, self).save(*args, **kwargs)         # Adds the number         self.slug = str(self.title.slug) + '-' + str(self.number)         # Calls the parent save() again         super(Issue, self).save(*args, **kwargs)

So, for example, when you save the Issue model in the Django admin, the slug field generates something like this, comics.emmafrostfiles.com/issues/astonishing-x-men-12 – which, by the way, has one of my favorite variant covers!

I had about 900 issues that needed to be “slugged.” Of course, I didn’t click “save” on each issue 900 times – that would have been too tedious. Login to SSH and save all the objects in the model you need slugged:

>>> from myproject.comics.models import Issue
>>> for issue in Issue.objects.all():
… issue.save()

I actually ran into a problem that did not throw me an error – but it was a simple fix. Make sure your character length for the slugs are right. You’ll have to go into your database admin to edit the length.

Good luck!


0 Comments

Hello Family, Hello Friends, and Hello world!

01.29.12 Posted in General by

Saying “Hello, Hello, Hello” a bunch of times makes it sound weird. Then again, I tend to run into that weirdness when I say a word too much.

Here’s to starting my personal blog. I hope the information can be of help to you!


Follow

Get every new post on this blog delivered to your Inbox.

Join other followers: